summaryrefslogtreecommitdiff
path: root/src/filelock.c
diff options
context:
space:
mode:
authorGerd Moellmann <gerd@gnu.org>2000-04-14 13:03:20 +0000
committerGerd Moellmann <gerd@gnu.org>2000-04-14 13:03:20 +0000
commitc1355e1fb481abbb1dba9f8d5229960252b2d43f (patch)
treed5914d4a2e17f818380d15dbb4c6f5a015b595b6 /src/filelock.c
parent33744b5de6c58f5ddb335b5550a49c0972012054 (diff)
downloademacs-c1355e1fb481abbb1dba9f8d5229960252b2d43f.tar.gz
(MAKE_LOCK_NAME): Allocate 2 more bytes.
(fill_in_lock_file_name): Avoid existing files that aren't links.
Diffstat (limited to 'src/filelock.c')
-rw-r--r--src/filelock.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/filelock.c b/src/filelock.c
index 8fb41a3d7eb..02b3ccc8b05 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -311,9 +311,11 @@ typedef struct
/* 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 @@ fill_in_lock_file_name (lockfile, fn)
register Lisp_Object fn;
{
register char *p;
+ struct stat st;
+ int count = 0;
strcpy (lockfile, XSTRING (fn)->data);
@@ -334,6 +338,18 @@ fill_in_lock_file_name (lockfile, fn)
/* 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.