Changeset 11012


Ignore:
Timestamp:
Oct 7, 2008, 10:58:38 PM (11 years ago)
Author:
gb
Message:

Prefer the convention of deriving the heap image name from the kernel
name by appending ".image". On platfroms where we've traditionally
used case-inversion, fall back to that if the .image doesn't exist
and the inverted name does.

(Need to compile this on a few platffors; not sure how easy it is to
use vanilla 'stat' on Windows.)

Also need to change the defaults in compile-ccl.lisp, and change the
documentation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/pmcl-kernel.c

    r10965 r11012  
    116116
    117117#include <fenv.h>
     118#include <sys/stat.h>
    118119
    119120#ifndef MAP_NORESERVE
     
    794795
    795796
    796 #if defined(DARWIN) || defined(WINDOWS)
     797/* Check for the existence of a file named by 'path'; return true
     798   if it seems to exist, without checking size, permissions, or
     799   anything else. */
     800Boolean
     801probe_file(char *path)
     802{
     803  struct stat st;
     804
     805  return (stat(path,&st) == 0);
     806}
     807
     808
    797809#ifdef WINDOWS
    798810/* Chop the trailing ".exe" from the kernel image name */
     
    812824#endif
    813825
     826char *
     827path_by_appending_image(char *path)
     828{
     829  int len = strlen(path) + strlen(".image") + 1;
     830  char *copy = (char *) malloc(len);
     831
     832  if (copy) {
     833    strcpy(copy, path);
     834    strcat(copy, ".image");
     835  }
     836  return copy;
     837}
     838
     839char *
     840case_inverted_path(char *path)
     841{
     842  char *copy = strdup(path), *base = copy, *work = copy, c;
     843  if (copy == NULL) {
     844    return NULL;
     845  }
     846  while(*work) {
     847    if (*work++ == '/') {
     848      base = work;
     849    }
     850  }
     851  work = base;
     852  while ((c = *work) != '\0') {
     853    if (islower(c)) {
     854      *work++ = toupper(c);
     855    } else {
     856      *work++ = tolower(c);
     857    }
     858  }
     859  return copy;
     860}
    814861/*
    815862   The underlying file system may be case-insensitive (e.g., HFS),
     
    825872  char *path = orig;
    826873#endif
    827   int len = strlen(path) + strlen(".image") + 1;
    828   char *copy = (char *) malloc(len);
    829 
    830   if (copy) {
    831     strcpy(copy, path);
    832     strcat(copy, ".image");
    833   }
    834   return copy;
    835 }
    836 
    837 #else
    838 char *
    839 default_image_name(char *orig)
    840 {
    841   char *copy = strdup(orig), *base = copy, *work = copy, c;
    842   if (copy == NULL) {
    843     return NULL;
    844   }
    845   while(*work) {
    846     if (*work++ == '/') {
    847       base = work;
    848     }
    849   }
    850   work = base;
    851   while ((c = *work) != '\0') {
    852     if (islower(c)) {
    853       *work++ = toupper(c);
    854     } else {
    855       *work++ = tolower(c);
    856     }
    857   }
    858   return copy;
    859 }
    860 #endif
     874  char *image_name = path_by_appending_image(path);
     875#if !defined(WINDOWS) && !defined(DARWIN)
     876  if (!probe_file(image_name)) {
     877    char *legacy = case_inverted_path(path);
     878    if (probe_file(legacy)) {
     879      image_name = legacy;
     880    }
     881  }
     882#endif
     883  return image_name;
     884}
     885
    861886
    862887
Note: See TracChangeset for help on using the changeset viewer.