/* 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
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);
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_;
/* 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, '/');
\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
|| !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")
|| (*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
#else
FILE *f = fopen (name, "r");
if (!f)
- return 0;
+ return false;
fclose (f);
- return 1;
+ return true;
#endif
}