Whitespace changes only
[pspp-builds.git] / src / data / file-name.c
index 8211e55d5db3a255405d98f16a841b5dc8d0aa2e..57dfe08d0bc3f17d1fce15e5e03a7f47aa856df9 100644 (file)
@@ -1,6 +1,5 @@
 /* PSPP - computes sample statistics.
    Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
-   Written by Ben Pfaff <blp@gnu.org>.
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -146,7 +145,7 @@ fn_tilde_expand (const char *input)
           pwd = getpwnam (ds_cstr (&user_name));
           if (pwd != NULL && pwd->pw_dir[0] != '\0')
             {
-              home = pwd->pw_dir;
+              home = xstrdup (pwd->pw_dir);
               remainder = input + 1 + ds_length (&user_name);
             }
           ds_destroy (&user_name);
@@ -175,13 +174,9 @@ fn_tilde_expand (const char *input)
    given by PATH, which is tilde- and environment-interpolated.
    Directories in PATH are delimited by ':'.  Returns the
    malloc'd full name of the first file found, or NULL if none is
-   found.
-
-   If PREFIX is non-NULL, then it is prefixed to each file name;
-   i.e., it looks like PREFIX/PATH_COMPONENT/NAME.  This is not
-   done with absolute directories in the path. */
+   found. */
 char *
-fn_search_path (const char *base_name, const char *path_, const char *prefix)
+fn_search_path (const char *base_name, const char *path_)
 {
   struct string path;
   struct substring dir_;
@@ -212,11 +207,6 @@ fn_search_path (const char *base_name, const char *path_, const char *prefix)
 
       /* Construct file name. */
       ds_clear (&file);
-      if (prefix != NULL && !fn_is_absolute (ds_cstr (&dir)))
-       {
-         ds_put_cstr (&file, prefix);
-         ds_put_char (&file, '/');
-       }
       ds_put_cstr (&file, ds_cstr (&dir));
       if (!ds_is_empty (&file) && ds_last (&file) != '/')
        ds_put_char (&file, '/');
@@ -493,8 +483,8 @@ fn_get_cwd (void)
 \f
 /* Find out information about files. */
 
-/* Returns nonzero iff NAME specifies an absolute file name. */
-int
+/* Returns true iff NAME specifies an absolute file name. */
+bool
 fn_is_absolute (const char *name)
 {
 #ifdef unix
@@ -502,21 +492,21 @@ fn_is_absolute (const char *name)
       || !strncmp (name, "./", 2)
       || !strncmp (name, "../", 3)
       || name[0] == '~')
-    return 1;
+    return true;
 #elif defined (__MSDOS__)
   if (name[0] == '\\'
       || !strncmp (name, ".\\", 2)
       || !strncmp (name, "..\\", 3)
       || (name[0] && name[1] == ':'))
-    return 1;
+    return true;
 #endif
   
-  return 0;
+  return false;
 }
   
-/* Returns 1 if FILE_NAME is a virtual file that doesn't
-   really exist on disk, 0 if it's a real file name. */
-int
+/* Returns true if FILE_NAME is a virtual file that doesn't
+   really exist on disk, false if it's a real file name. */
+bool
 fn_is_special (const char *file_name)
 {
   if (!strcmp (file_name, "-") || !strcmp (file_name, "stdin")
@@ -526,13 +516,13 @@ fn_is_special (const char *file_name)
       || (*file_name && file_name[strlen (file_name) - 1] == '|')
 #endif
       )
-    return 1;
+    return true;
 
-  return 0;
+  return false;
 }
 
-/* Returns nonzero if file with name NAME exists. */
-int
+/* Returns true if file with name NAME exists. */
+bool
 fn_exists (const char *name)
 {
 #ifdef unix
@@ -542,9 +532,9 @@ fn_exists (const char *name)
 #else
   FILE *f = fopen (name, "r");
   if (!f)
-    return 0;
+    return false;
   fclose (f);
-  return 1;
+  return true;
 #endif
 }