changeset 28589:f10b492946d2

(MAKE_LOCK_NAME): Allocate 2 more bytes. (fill_in_lock_file_name): Avoid existing files that aren't links.
author Gerd Moellmann <gerd@gnu.org>
date Fri, 14 Apr 2000 13:03:20 +0000
parents 5ab6194573ed
children 784c31479eb2
files src/filelock.c
diffstat 1 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/filelock.c	Fri Apr 14 12:47:38 2000 +0000
+++ b/src/filelock.c	Fri Apr 14 13:03:20 2000 +0000
@@ -311,9 +311,11 @@
 
 
 /* Write the name of the lock file for FN into LFNAME.  Length will be
-   that of FN plus two more for the leading `.#' plus one for the null.  */
+   that of FN plus two more for the leading `.#' plus 1 for the
+   trailing period plus one for the digit after it plus one for the
+   null.  */
 #define MAKE_LOCK_NAME(lock, file) \
-  (lock = (char *) alloca (STRING_BYTES (XSTRING (file)) + 2 + 1), \
+  (lock = (char *) alloca (STRING_BYTES (XSTRING (file)) + 2 + 1 + 1 + 1), \
    fill_in_lock_file_name (lock, (file)))
 
 static void
@@ -322,6 +324,8 @@
      register Lisp_Object fn;
 {
   register char *p;
+  struct stat st;
+  int count = 0;
 
   strcpy (lockfile, XSTRING (fn)->data);
 
@@ -334,6 +338,18 @@
   /* Insert the `.#'.  */
   p[1] = '.';
   p[2] = '#';
+
+  p = p + strlen (p);
+
+  while (lstat (lockfile, &st) == 0 && !S_ISLNK (st.st_mode))
+    {
+      if (count > 9)
+	{
+	  *p = '\0';
+	  return;
+	}
+      sprintf (p, ".%d", count++);
+    }
 }
 
 /* Lock the lock file named LFNAME.