Add scratch file handles.
[pspp-builds.git] / src / filename.c
index b8f8332fdb9057f753435aedd92e84ae33d27d14..0c085776f5b889aefc23dfc9fb8174273bcc759e 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - computes sample statistics.
-   Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+   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
@@ -530,6 +530,18 @@ fn_basename (const char *filename)
   abort ();
 }
 #endif
+
+/* Returns the extension part of FILENAME as a malloc()'d string.
+   If FILENAME does not have an extension, returns an empty
+   string. */
+char *
+fn_extension (const char *filename) 
+{
+  const char *extension = strrchr (filename, '.');
+  if (extension == NULL)
+    extension = "";
+  return xstrdup (extension);
+}
 \f
 #if unix
 /* Returns the current working directory, as a malloc()'d string.
@@ -691,7 +703,7 @@ fn_open (const char *fn, const char *mode)
 #ifdef unix
   if (fn[0] == '|')
     {
-      if (safer_mode())
+      if (get_safer_mode ())
        return safety_violation (fn);
 
       return popen (&fn[1], mode);
@@ -701,7 +713,7 @@ fn_open (const char *fn, const char *mode)
       char *s;
       FILE *f;
 
-      if (safer_mode())
+      if (get_safer_mode ())
        return safety_violation (fn);
       
       s = local_alloc (strlen (fn));