[project @ 2001-05-21 11:02:15 by simonmar]
authorsimonmar <unknown>
Mon, 21 May 2001 11:02:15 +0000 (11:02 +0000)
committersimonmar <unknown>
Mon, 21 May 2001 11:02:15 +0000 (11:02 +0000)
Re-instate the missing fstat call.

By some bizarre coincidence, this function declared a 'struct stat',
and failed to initialize it, but in practice the uninitialized memory
was in the exact same place on the stack as the struct stat from a
previous call to fstat, which meant all the tests worked :-)

Also, apparently gcc doesn't warn about uninitialised use of structure
fields.

ghc/lib/std/cbits/lockFile.c

index 14a0a38..f6a9aea 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
  *
- * $Id: lockFile.c,v 1.1 2001/05/18 16:54:06 simonmar Exp $
+ * $Id: lockFile.c,v 1.2 2001/05/21 11:02:15 simonmar Exp $
  *
  * stdin/stout/stderr Runtime Support
  */
@@ -27,8 +27,21 @@ static int writeLocks = 0;
 int
 lockFile(int fd, int for_writing, int exclusive)
 {
-    int i;
     struct stat sb;
+    int i;
+
+    while (fstat(fd, &sb) < 0) {
+       if (errno != EINTR) {
+#ifndef _WIN32
+           return -1;
+#else
+           /* fstat()ing socket fd's seems to fail with CRT's fstat(),
+              so let's just silently return and hope for the best..
+           */
+           return 0;
+#endif
+       }
+    }
 
     if (for_writing) {
       /* opening a file for writing, check to see whether