/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <unistd.h>
#include "data/settings.h"
-#include "libpspp/hash.h"
+#include "libpspp/hash-functions.h"
#include "libpspp/message.h"
#include "libpspp/str.h"
#include "libpspp/version.h"
#include "gl/dirname.h"
+#include "gl/dosname.h"
#include "gl/intprops.h"
#include "gl/minmax.h"
#include "gl/relocatable.h"
return false;
}
-/* Returns true if file with name NAME exists. */
+/* Returns true if file with name NAME exists, and that file is not a
+ directory */
bool
fn_exists (const char *name)
{
struct stat temp;
- return stat (name, &temp) == 0;
+ if ( stat (name, &temp) != 0 )
+ return false;
+
+ return ! S_ISDIR (temp.st_mode);
}
\f
/* Environment variables. */
static FILE *
safety_violation (const char *fn)
{
- msg (SE, _("Not opening pipe file `%s' because SAFER option set."), fn);
+ msg (SE, _("Not opening pipe file `%s' because %s option set."), fn, "SAFER");
errno = EPERM;
return NULL;
}
}
else
#endif
- {
- FILE *f = fopen (fn, mode);
-
- if (f && mode[0] != 'r')
- setvbuf (f, NULL, _IOLBF, 0);
-
- return f;
- }
+ return fopen (fn, mode);
}
/* Counterpart to fn_open that closes file F with name FN; returns 0
return fclose (f);
}
-/* Creates a new file named FN with the given PERMISSIONS bits,
- and returns a stream for it or a null pointer on failure.
- MODE should be "w" or "wb". */
-FILE *
-create_stream (const char *fn, const char *mode, mode_t permissions)
-{
- int fd;
- FILE *stream;
-
- fd = open (fn, O_WRONLY | O_CREAT | O_TRUNC, permissions);
- if (fd < 0)
- return NULL;
-
- stream = fdopen (fd, mode);
- if (stream == NULL)
- {
- int save_errno = errno;
- close (fd);
- errno = save_errno;
- }
-
- return stream;
-}
/* A file's identity: