]> diplodocus.org Git - nmh/blobdiff - sbr/lock_file.c
Silence more gcc format-string warnings.
[nmh] / sbr / lock_file.c
index cac80c1b1abfb79df361aad308116fc6c704bcc5..c3dbbd9cf057011b7edce3313c0a3dbbefa9c6ff 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * lock.c -- routines to lock/unlock files
+/* lock_file.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
@@ -19,6 +17,8 @@
 #include <h/signals.h>
 #include <h/utils.h>
 #include <h/mts.h>
+#include "lock_file.h"
+#include "m_mktemp.h"
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -73,15 +73,9 @@ struct lock {
 
 enum locktype { FCNTL_LOCKING, FLOCK_LOCKING, LOCKF_LOCKING, DOT_LOCKING };
 
-/*
- * Flags to indicate whether we've initialized the lock types, and
- * our saved lock types
- */
-static int datalockinit = 0;
-static int spoollockinit = 0;
+/* Our saved lock types. */
 static enum locktype datalocktype, spoollocktype;
 
-
 /* top of list containing all open locks */
 static struct lock *l_top = NULL;
 
@@ -117,17 +111,18 @@ static int lockit (struct lockinfo *);
 int
 lkopendata(const char *file, int access, mode_t mode, int *failed_to_lock)
 {
-    if (! datalockinit) {
-       char *cp = context_find("datalocking");
+    static bool deja_vu;
+
+    if (!deja_vu) {
+        char *dl;
 
-       if (cp) {
-           datalocktype = init_locktype(cp);
+        deja_vu = true;
+       if ((dl = context_find("datalocking"))) {
+           datalocktype = init_locktype(dl);
        } else {
            /* We default to fcntl locking for data files */
            datalocktype = FCNTL_LOCKING;
        }
-
-       datalockinit = 1;
     }
 
     return lkopen(file, access, mode, datalocktype, failed_to_lock);
@@ -140,10 +135,11 @@ lkopendata(const char *file, int access, mode_t mode, int *failed_to_lock)
 
 int lkopenspool(const char *file, int access, mode_t mode, int *failed_to_lock)
 {
-    if (! spoollockinit) {
-       spoollocktype = init_locktype(spoollocking);
+    static bool deja_vu;
 
-       spoollockinit = 1;
+    if (!deja_vu) {
+       deja_vu = true;
+        spoollocktype = init_locktype(spoollocking);
     }
 
     return lkopen(file, access, mode, spoollocktype, failed_to_lock);