- * lock.c -- routines to lock/unlock files
- *
- * This code is Copyright (c) 2002, by the authors of nmh. See the
- * COPYRIGHT file in the root directory of the nmh distribution for
- * complete copyright information.
- */
-
-/* Modified by Ruud de Rooij to support Miquel van Smoorenburg's liblockfile
- *
- * Since liblockfile locking shares most of its code with dot locking, it
- * is enabled by defining both DOT_LOCKING and HAVE_LIBLOCKFILE.
- *
- * Ruud de Rooij <ruud@debian.org> Sun, 28 Mar 1999 15:34:03 +0200
- */
+** lock.c -- routines to lock/unlock files
+**
+** This code is Copyright (c) 2002, by the authors of nmh. See the
+** COPYRIGHT file in the root directory of the nmh distribution for
+** complete copyright information.
+*/
+
+/*
+** Modified by Ruud de Rooij to support Miquel van Smoorenburg's liblockfile
+**
+** Since liblockfile locking shares most of its code with dot locking, it
+** is enabled by defining both DOT_LOCKING and HAVE_LIBLOCKFILE.
+**
+** Ruud de Rooij <ruud@debian.org> Sun, 28 Mar 1999 15:34:03 +0200
+*/
-static int lkopen_dot (char *, int, mode_t);
-static void lockname (char *, struct lockinfo *, int);
-static void timerON (char *, int);
-static void timerOFF (int);
-static RETSIGTYPE alrmser (int);
+static int lkopen_dot(char *, int, mode_t);
+static void lockname(char *, struct lockinfo *, int);
+static void timerON(char *, int);
+static void timerOFF(int);
+static RETSIGTYPE alrmser(int);
- * Base routine to open and lock a file,
- * and return a file descriptor.
- */
+** Base routine to open and lock a file,
+** and return a file descriptor.
+*/
- * Base routine to close and unlock a file,
- * given a file descriptor.
- */
+** Base routine to close and unlock a file,
+** given a file descriptor.
+*/
- lseek (fd, (off_t) 0, SEEK_SET);
- lockf (fd, F_ULOCK, 0L);
+ lseek(fd, (off_t) 0, SEEK_SET);
+ lockf(fd, F_ULOCK, 0L);
- * Base routine to open and lock a file,
- * and return a FILE pointer
- */
+** Base routine to open and lock a file,
+** and return a FILE pointer
+*/
- fseek (fp, 0L, SEEK_SET);
- lockf (fileno(fp), F_ULOCK, 0L);
+ fseek(fp, 0L, SEEK_SET);
+ lockf(fileno(fp), F_ULOCK, 0L);
- * Get the name of the eventual lock file, as well
- * as a name for a temporary lock file.
- */
- lockname (file, &lkinfo, 1);
+ ** Get the name of the eventual lock file, as well
+ ** as a name for a temporary lock file.
+ */
+ lockname(file, &lkinfo, 1);
- * Abort locking, if we fail to lock after 5 attempts
- * and are never able to stat the lock file.
- */
+ ** Abort locking, if we fail to lock after 5
+ ** attempts and are never able to stat the
+ ** lock file.
+ */
- snprintf (buffer, sizeof(buffer), "nmh lock: pid %d\n", (int) getpid());
+ snprintf(buffer, sizeof(buffer), "nmh lock: pid %d\n", (int) getpid());
- snprintf (bp, sizeof(li->curlock), "%s/", lockdir);
- tmplen = strlen (bp);
+ snprintf(bp, sizeof(li->curlock), "%s/", lockdir);
+ tmplen = strlen(bp);
- snprintf (bp, sizeof(li->curlock), "%.*s", (int)(cp - file), file);
- tmplen = strlen (bp);
+ snprintf(bp, sizeof(li->curlock), "%.*s", (int)(cp - file), file);
+ tmplen = strlen(bp);
-#if 0
- /*
- * mmdf style dot locking. Currently not supported.
- * If we start supporting mmdf style dot locking,
- * we will need to change the return value of lockname
- */
- if (stat (file, &st) == -1)
- return -1;
-
- snprintf (bp, sizeof(li->curlock) - bplen, "LCK%05d.%05d",
- st.st_dev, st.st_ino);
-#endif
-
- snprintf (bp, sizeof(li->curlock) - bplen, "%s.lock", cp);
+ snprintf(bp, sizeof(li->curlock) - bplen, "%s.lock", cp);
- * If this is for a new lock, create a name for
- * the temporary lock file for lockit()
- */
+ ** If this is for a new lock, create a name for
+ ** the temporary lock file for lockit()
+ */
- if ((cp = strrchr (li->curlock, '/')) == NULL || *++cp == 0)
- strncpy (li->tmplock, ",LCK.XXXXXX", sizeof(li->tmplock));
+ if ((cp = strrchr(li->curlock, '/')) == NULL || *++cp == 0)
+ strncpy(li->tmplock, ",LCK.XXXXXX", sizeof(li->tmplock));
- snprintf (li->tmplock, sizeof(li->tmplock), "%.*s,LCK.XXXXXX",
- (int)(cp - li->curlock), li->curlock);
+ snprintf(li->tmplock, sizeof(li->tmplock),
+ "%.*s,LCK.XXXXXX",
+ (int)(cp - li->curlock), li->curlock);
- lp->l_lock = mh_xmalloc (len);
- memcpy (lp->l_lock, curlock, len);
+ lp->l_lock = mh_xmalloc(len);
+ memcpy(lp->l_lock, curlock, len);
- * Search through the list of lockfiles for the
- * current lockfile, and remove it from the list.
- */
+** Search through the list of lockfiles for the
+** current lockfile, and remove it from the list.
+*/
- * If timer goes off, we update the ctime of all open
- * lockfiles, so another command doesn't remove them.
- */
+** If timer goes off, we update the ctime of all open
+** lockfiles, so another command doesn't remove them.
+*/