]> code.delx.au - gnu-emacs/blobdiff - src/filelock.c
* src/macfont.m (mac_font_shape): Make sure that total_advance is increasing.
[gnu-emacs] / src / filelock.c
index 89d3e3502194c9951239822282c247f8b27a454c..2f92e0fdc83f5b868442a91abd393ed9b7decef1 100644 (file)
@@ -1,6 +1,6 @@
 /* Lock files for editing.
 
-Copyright (C) 1985-1987, 1993-1994, 1996, 1998-2015 Free Software
+Copyright (C) 1985-1987, 1993-1994, 1996, 1998-2016 Free Software
 Foundation, Inc.
 
 Author: Richard King
@@ -10,8 +10,8 @@ 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 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -45,16 +45,16 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <c-ctype.h>
 
 #include "lisp.h"
-#include "character.h"
 #include "buffer.h"
 #include "coding.h"
-#include "systime.h"
 #ifdef WINDOWSNT
 #include <share.h>
 #include <sys/socket.h>        /* for fcntl */
 #include "w32.h"       /* for dostounix_filename */
 #endif
 
+#ifndef MSDOS
+
 #ifdef HAVE_UTMP_H
 #include <utmp.h>
 #endif
@@ -65,7 +65,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #define BOOT_TIME_FILE "/var/run/random-seed"
 #endif
 
-#ifndef WTMP_FILE
+#if !defined WTMP_FILE && !defined WINDOWSNT
 #define WTMP_FILE "/var/log/wtmp"
 #endif
 
@@ -193,14 +193,11 @@ get_boot_time (void)
   /* If we did not find a boot time in wtmp, look at wtmp, and so on.  */
   for (counter = 0; counter < 20 && ! boot_time; counter++)
     {
+      Lisp_Object filename = Qnil;
+      bool delete_flag = false;
       char cmd_string[sizeof WTMP_FILE ".19.gz"];
-      Lisp_Object tempname, filename;
-      bool delete_flag = 0;
-
-      filename = Qnil;
-
-      tempname = make_formatted_string
-       (cmd_string, "%s.%d", WTMP_FILE, counter);
+      AUTO_STRING_WITH_LEN (tempname, cmd_string,
+                           sprintf (cmd_string, "%s.%d", WTMP_FILE, counter));
       if (! NILP (Ffile_exists_p (tempname)))
        filename = tempname;
       else
@@ -220,7 +217,7 @@ get_boot_time (void)
              CALLN (Fcall_process, build_string ("gzip"), Qnil,
                     list2 (QCfile, filename), Qnil,
                     build_string ("-cd"), tempname);
-             delete_flag = 1;
+             delete_flag = true;
            }
        }
 
@@ -255,14 +252,7 @@ get_boot_time_1 (const char *filename, bool newest)
   struct utmp ut, *utp;
 
   if (filename)
-    {
-      /* On some versions of IRIX, opening a nonexistent file name
-        is likely to crash in the utmp routines.  */
-      if (faccessat (AT_FDCWD, filename, R_OK, AT_EACCESS) != 0)
-       return;
-
-      utmpname (filename);
-    }
+    utmpname (filename);
 
   setutent ();
 
@@ -497,7 +487,7 @@ read_lock_data (char *lfname, char lfinfo[MAX_LFINFO + 1])
   while ((nbytes = readlinkat (AT_FDCWD, lfname, lfinfo, MAX_LFINFO + 1)) < 0
         && errno == EINVAL)
     {
-      int fd = emacs_open (lfname, O_RDONLY | O_BINARY | O_NOFOLLOW, 0);
+      int fd = emacs_open (lfname, O_RDONLY | O_NOFOLLOW, 0);
       if (0 <= fd)
        {
          /* Use read, not emacs_read, since FD isn't unwind-protected.  */
@@ -666,13 +656,8 @@ lock_file (Lisp_Object fn)
   Lisp_Object orig_fn, encoded_fn;
   char *lfname;
   lock_info_type lock_info;
-  struct gcpro gcpro1;
   USE_SAFE_ALLOCA;
 
-  /* Don't do locking if the user has opted out.  */
-  if (! create_lockfiles)
-    return;
-
   /* Don't do locking while dumping Emacs.
      Uncompressing wtmp files uses call-process, which does not work
      in an uninitialized Emacs.  */
@@ -680,7 +665,6 @@ lock_file (Lisp_Object fn)
     return;
 
   orig_fn = fn;
-  GCPRO1 (fn);
   fn = Fexpand_file_name (fn, Qnil);
 #ifdef WINDOWSNT
   /* Ensure we have only '/' separators, to avoid problems with
@@ -690,9 +674,6 @@ lock_file (Lisp_Object fn)
 #endif
   encoded_fn = ENCODE_FILE (fn);
 
-  /* Create the name of the lock-file for file fn */
-  MAKE_LOCK_NAME (lfname, encoded_fn);
-
   /* See if this file is visited and has changed on disk since it was
      visited.  */
   {
@@ -707,27 +688,33 @@ lock_file (Lisp_Object fn)
 
   }
 
-  /* Try to lock the lock.  */
-  if (0 < lock_if_free (&lock_info, lfname))
+  /* Don't do locking if the user has opted out.  */
+  if (create_lockfiles)
     {
-      /* Someone else has the lock.  Consider breaking it.  */
-      Lisp_Object attack;
-      char *dot = lock_info.dot;
-      ptrdiff_t pidlen = lock_info.colon - (dot + 1);
-      static char const replacement[] = " (pid ";
-      int replacementlen = sizeof replacement - 1;
-      memmove (dot + replacementlen, dot + 1, pidlen);
-      strcpy (dot + replacementlen + pidlen, ")");
-      memcpy (dot, replacement, replacementlen);
-      attack = call2 (intern ("ask-user-about-lock"), fn,
-                     build_string (lock_info.user));
-      /* Take the lock if the user said so.  */
-      if (!NILP (attack))
-       lock_file_1 (lfname, 1);
-    }
 
-  UNGCPRO;
-  SAFE_FREE ();
+      /* Create the name of the lock-file for file fn */
+      MAKE_LOCK_NAME (lfname, encoded_fn);
+
+      /* Try to lock the lock.  */
+      if (0 < lock_if_free (&lock_info, lfname))
+       {
+         /* Someone else has the lock.  Consider breaking it.  */
+         Lisp_Object attack;
+         char *dot = lock_info.dot;
+         ptrdiff_t pidlen = lock_info.colon - (dot + 1);
+         static char const replacement[] = " (pid ";
+         int replacementlen = sizeof replacement - 1;
+         memmove (dot + replacementlen, dot + 1, pidlen);
+         strcpy (dot + replacementlen + pidlen, ")");
+         memcpy (dot, replacement, replacementlen);
+         attack = call2 (intern ("ask-user-about-lock"), fn,
+                         build_string (lock_info.user));
+         /* Take the lock if the user said so.  */
+         if (!NILP (attack))
+           lock_file_1 (lfname, 1);
+       }
+      SAFE_FREE ();
+    }
 }
 
 void
@@ -747,6 +734,19 @@ unlock_file (Lisp_Object fn)
   SAFE_FREE ();
 }
 
+#else  /* MSDOS */
+void
+lock_file (Lisp_Object fn)
+{
+}
+
+void
+unlock_file (Lisp_Object fn)
+{
+}
+
+#endif /* MSDOS */
+
 void
 unlock_all_files (void)
 {
@@ -810,6 +810,9 @@ The value is nil if the FILENAME is not locked,
 t if it is locked by you, else a string saying which user has locked it.  */)
   (Lisp_Object filename)
 {
+#ifdef MSDOS
+  return Qnil;
+#else
   Lisp_Object ret;
   char *lfname;
   int owner;
@@ -830,6 +833,7 @@ t if it is locked by you, else a string saying which user has locked it.  */)
 
   SAFE_FREE ();
   return ret;
+#endif
 }
 
 void