X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Ffile-name.c;h=272e555bf89965c3ebd282531781d0c50f4f244a;hb=9691c54c1a51792e21c10bbee7a66f5934b96349;hp=2fd79428e2409fc850e6c644503ad8e6e1778cc7;hpb=707848060e414fe93458834446dd7cdbf800667f;p=pspp-builds.git diff --git a/src/data/file-name.c b/src/data/file-name.c index 2fd79428..272e555b 100644 --- a/src/data/file-name.c +++ b/src/data/file-name.c @@ -138,6 +138,7 @@ fn_search_path (const char *base_name, const char *path_) if (!ds_is_empty (&file) && !ISSLASH (ds_last (&file))) ds_put_char (&file, '/'); ds_put_cstr (&file, base_name); + ds_relocate (&file); /* Check whether file exists. */ if (fn_exists (ds_cstr (&file))) @@ -269,7 +270,7 @@ fn_open (const char *fn, const char *mode) #if HAVE_POPEN if (fn[0] == '|') { - if (get_safer_mode ()) + if (settings_get_safer_mode ()) return safety_violation (fn); return popen (&fn[1], mode[0] == 'r' ? "r" : "w"); @@ -279,7 +280,7 @@ fn_open (const char *fn, const char *mode) char *s; FILE *f; - if (get_safer_mode ()) + if (settings_get_safer_mode ()) return safety_violation (fn); s = xmalloca (strlen (fn)); @@ -411,7 +412,7 @@ fn_get_identity (const char *file_name) identity->device = 0; identity->inode = 0; identity->name = xstrdup (ok ? cname : file_name); - str_lowercase (identity->file_name); + str_lowercase (identity->name); #endif /* Windows */ return identity; @@ -452,3 +453,59 @@ fn_hash_identity (const struct file_identity *identity) hash ^= hsh_hash_string (identity->name); return hash; } + +#ifdef WIN32 + +/* Apparently windoze users like to see output dumped into their home directory, + not the current directory (!) */ +const char * +default_output_path (void) +{ + static char *path = NULL; + + if ( path == NULL) + { + /* Windows NT defines HOMEDRIVE and HOMEPATH. But give preference + to HOME, because the user can change HOME. */ + + const char *home_dir = getenv ("HOME"); + int i; + + if (home_dir == NULL) + { + const char *home_drive = getenv ("HOMEDRIVE"); + const char *home_path = getenv ("HOMEPATH"); + + + if (home_drive != NULL && home_path != NULL) + home_dir = xasprintf ("%s%s", + home_drive, home_path); + } + + if (home_dir == NULL) + home_dir = "c:/users/default"; /* poor default */ + + path = xasprintf ("%s%c", home_dir, '/'); + + + for(i = 0; i < strlen (path); i++) + if (path[i] == '\\') path[i] = '/'; + } + + return path; +} + +#else + +/* ... whereas the rest of the world just likes it to be + put "here" for easy access. */ +const char * +default_output_path (void) +{ + static char current_dir[] = ""; + + return current_dir; +} + +#endif +