entered into RCS
[bpt/emacs.git] / src / fileio.c
index ea7f8c6..4ff7dfe 100644 (file)
@@ -1,11 +1,11 @@
 /* File IO for GNU Emacs.
-   Copyright (C) 1985, 1986, 1987, 1988 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1987, 1988, 1992 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 1, or (at your option)
+the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
+#include "config.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -52,7 +53,6 @@ extern int sys_nerr;
 #include <sys/time.h>
 #endif
 
-#include "config.h"
 #include "lisp.h"
 #include "buffer.h"
 #include "window.h"
@@ -411,7 +411,7 @@ directory_file_name (src, dst)
   /* Process as Unix format: just remove any final slash.
      But leave "/" unchanged; do not change it to "".  */
   strcpy (dst, src);
-  if (dst[slen - 1] == '/' && slen > 1)
+  if (slen > 1 && dst[slen - 1] == '/')
     dst[slen - 1] = 0;
   return 1;
 }
@@ -621,7 +621,7 @@ See also the function `substitute-in-file-name'.")
 #ifdef VMS
        || nm[1] == ':'
 #endif /* VMS */
-       || nm[1] == 0)/* ~/filename */
+       || nm[1] == 0)/* ~ by itself */
       {
        if (!(newdir = (unsigned char *) egetenv ("HOME")))
          newdir = (unsigned char *) "";
@@ -642,15 +642,18 @@ See also the function `substitute-in-file-name'.")
        o [p - nm] = 0;
 
        pw = (struct passwd *) getpwnam (o + 1);
-       if (!pw)
-         error ("\"%s\" isn't a registered user", o + 1);
-
+       if (pw)
+         {
+           newdir = (unsigned char *) pw -> pw_dir;
 #ifdef VMS
-       nm = p + 1;             /* skip the terminator */
+           nm = p + 1;         /* skip the terminator */
 #else
-       nm = p;
+           nm = p;
 #endif /* VMS */
-       newdir = (unsigned char *) pw -> pw_dir;
+         }
+
+       /* If we don't find a user of that name, leave the name
+          unchanged; don't move nm forward to p.  */
       }
 
   if (nm[0] != '/'
@@ -794,7 +797,8 @@ See also the function `substitute-in-file-name'.")
   return make_string (target, o - target);
 }
 #if 0
-DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
+/* Changed this DEFUN to a DEAFUN, so as not to confuse `make-docfile'.
+DEAFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
   "Convert FILENAME to absolute, and canonicalize it.\n\
 Second arg DEFAULT is directory to start with if FILENAME is relative\n\
  (does not start with slash); if DEFAULT is nil or missing,\n\
@@ -1459,8 +1463,8 @@ DEFUN ("make-directory", Fmake_directory, Smake_directory, 1, 1, "FMake director
     return Qnil;
 }
 
-DEFUN ("remove-directory", Fremove_directory, Sremove_directory, 1, 1, "FRemove directory: ",
-  "Remove a directory.  One argument, a file name string.")
+DEFUN ("delete-directory", Fdelete_directory, Sdelete_directory, 1, 1, "FDelete directory: ",
+  "Delete a directory.  One argument, a file name string.")
   (dirname)
      Lisp_Object dirname;
 {
@@ -1589,38 +1593,38 @@ Signals a `file-already-exists' error if a file NEWNAME already exists\n\
 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.\n\
 A number as third arg means request confirmation if NEWNAME already exists.\n\
 This happens for interactive use with M-x.")
-  (filename, newname, ok_if_already_exists)
-     Lisp_Object filename, newname, ok_if_already_exists;
+  (filename, linkname, ok_if_already_exists)
+     Lisp_Object filename, linkname, ok_if_already_exists;
 {
 #ifdef NO_ARG_ARRAY
   Lisp_Object args[2];
 #endif
   struct gcpro gcpro1, gcpro2;
 
-  GCPRO2 (filename, newname);
+  GCPRO2 (filename, linkname);
   CHECK_STRING (filename, 0);
-  CHECK_STRING (newname, 1);
+  CHECK_STRING (linkname, 1);
 #if 0 /* This made it impossible to make a link to a relative name.  */
   filename = Fexpand_file_name (filename, Qnil);
 #endif
-  newname = Fexpand_file_name (newname, Qnil);
+  linkname = Fexpand_file_name (linkname, Qnil);
   if (NILP (ok_if_already_exists)
       || XTYPE (ok_if_already_exists) == Lisp_Int)
-    barf_or_query_if_file_exists (newname, "make it a link",
+    barf_or_query_if_file_exists (linkname, "make it a link",
                                  XTYPE (ok_if_already_exists) == Lisp_Int);
-  if (0 > symlink (XSTRING (filename)->data, XSTRING (newname)->data))
+  if (0 > symlink (XSTRING (filename)->data, XSTRING (linkname)->data))
     {
       /* If we didn't complain already, silently delete existing file.  */
       if (errno == EEXIST)
        {
          unlink (XSTRING (filename)->data);
-         if (0 <= symlink (XSTRING (filename)->data, XSTRING (newname)->data))
+         if (0 <= symlink (XSTRING (filename)->data, XSTRING (linkname)->data))
            return Qnil;
        }
 
 #ifdef NO_ARG_ARRAY
       args[0] = filename;
-      args[1] = newname;
+      args[1] = linkname;
       report_file_error ("Making symbolic link", Flist (2, args));
 #else
       report_file_error ("Making symbolic link", Flist (2, &filename));
@@ -1930,6 +1934,18 @@ created files will not have that permission enabled.")
   return mask;
 }
 
+#ifdef unix
+
+DEFUN ("unix-sync", Funix_sync, Sunix_sync, 0, 0, "",
+  "Tell Unix to finish all pending disk updates.")
+  ()
+{
+  sync ();
+  return Qnil;
+}
+
+#endif /* unix */
+
 DEFUN ("file-newer-than-file-p", Ffile_newer_than_file_p, Sfile_newer_than_file_p, 2, 2, 0,
   "Return t if file FILE1 is newer than file FILE2.\n\
 If FILE1 does not exist, the answer is nil;\n\
@@ -2004,9 +2020,20 @@ before the error is signaled.")
 
   record_unwind_protect (close_file_unwind, make_number (fd));
 
+#ifdef S_IFSOCK
+  /* This code will need to be changed in order to work on named
+     pipes, and it's probably just not worth it.  So we should at
+     least signal an error.  */
+  if ((st.st_mode & S_IFMT) == S_IFSOCK)
+    Fsignal (Qfile_error,
+            Fcons (build_string ("reading from named pipe"),
+                   Fcons (filename, Qnil)));
+#endif
+
   /* Supposedly happens on VMS.  */
   if (st.st_size < 0)
     error ("File size is negative");
+
   {
     register Lisp_Object temp;
 
@@ -2443,11 +2470,11 @@ auto_save_error ()
 
   ring_bell ();
   message ("Autosaving...error for %s", name);
-  Fsleep_for (make_number (1));
+  Fsleep_for (make_number (1), Qnil);
   message ("Autosaving...error!for %s", name);
-  Fsleep_for (make_number (1));
+  Fsleep_for (make_number (1), Qnil);
   message ("Autosaving...error for %s", name);
-  Fsleep_for (make_number (1));
+  Fsleep_for (make_number (1), Qnil);
   return Qnil;
 }
 
@@ -2478,7 +2505,7 @@ Auto-saving writes the buffer into a file\n\
 so that your editing is not lost if the system crashes.\n\
 This file is not the file you visited; that changes only when you save.\n\n\
 Non-nil first argument means do not print any message if successful.\n\
-Non-nil second argumet means save only current buffer.")
+Non-nil second argument means save only current buffer.")
   (nomsg)
      Lisp_Object nomsg;
 {
@@ -2838,7 +2865,7 @@ nil means use format `var'.  This variable is meaningful only on VMS.");
   defsubr (&Ssubstitute_in_file_name);
   defsubr (&Scopy_file);
   defsubr (&Smake_directory);
-  defsubr (&Sremove_directory);
+  defsubr (&Sdelete_directory);
   defsubr (&Sdelete_file);
   defsubr (&Srename_file);
   defsubr (&Sadd_name_to_file);
@@ -2875,4 +2902,6 @@ nil means use format `var'.  This variable is meaningful only on VMS.");
 
   defsubr (&Sread_file_name_internal);
   defsubr (&Sread_file_name);
+
+  defsubr (&Sunix_sync);
 }