<<< Date Index >>>     <<< Thread Index >>>

patch for dotlock.c



The patch below allow mutt to run under Cygwin on Win9x/ME 
machines. These systems do not have hard links but emulate
them. Thus the test  "if (sb.st_nlink == 2)" always fails.

However the link() API succeeds only if the destination 
doesn't exist already. Thus one can break out of the loop
as soon as link() succeeds, there is no need to stat().

Parenthetically, note that exim has used this method for a long
time, which suggests that it is reliable on all systems.

Pierre


--- dotlock.c.orig      2003-10-20 22:11:36.000000000 -0400
+++ dotlock.c   2003-10-20 22:28:04.000000000 -0400
@@ -623,10 +623,14 @@ dotlock_lock (const char *realpath)
   
   while (hard_count++ < HARDMAXATTEMPTS)
   {
-
+    int res;
+  
     BEGIN_PRIVILEGED ();
-    link (nfslockfile, lockfile);
+    res = link (nfslockfile, lockfile);
     END_PRIVILEGED ();
+    
+    if (!res)
+      break;
 
     if (stat (nfslockfile, &sb) != 0)
     {