[project @ 2001-04-02 16:10:32 by rrt]
[ghc-hetmet.git] / ghc / lib / std / cbits / getLock.c
index be6acb4..7a82fbe 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
  *
- * $Id: getLock.c,v 1.4 1999/02/04 12:13:15 sof Exp $
+ * $Id: getLock.c,v 1.9 2001/04/02 16:10:32 rrt Exp $
  *
  * stdin/stout/stderr Runtime Support
  */
@@ -52,7 +52,14 @@ int exclusive;
 
     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
        }
     }
 
@@ -65,8 +72,12 @@ int exclusive;
          we don't have any read locks on it already.. */
       for (i = 0; i < readLocks; i++) {
         if (readLock[i].inode == sb.st_ino && readLock[i].device == sb.st_dev) {
+#ifndef __MINGW32__
            errno = EAGAIN;
            return -1;
+#else
+           break;    
+#endif
         }          
       }
       /* If we're determined that there is only a single
@@ -76,8 +87,12 @@ int exclusive;
       if (exclusive) {
        for (i = 0; i < writeLocks; i++) {
          if (writeLock[i].inode == sb.st_ino && writeLock[i].device == sb.st_dev) {
+#ifndef __MINGW32__
             errno = EAGAIN;
             return -1;
+#else
+            break;
+#endif
          }
         }
       }
@@ -92,8 +107,12 @@ int exclusive;
          that there's no-one writing to the underlying file. */
       for (i = 0; i < writeLocks; i++) {
        if (writeLock[i].inode == sb.st_ino && writeLock[i].device == sb.st_dev) {
-           errno = EAGAIN;
-           return -1;
+#ifndef __MINGW32__
+            errno = EAGAIN;
+            return -1;
+#else
+            break;
+#endif
         }
       }
       /* Fit in new entry, reusing an existing table entry, if possible. */
@@ -115,7 +134,7 @@ int
 unlockFile(fd)
 int fd;
 {
-    int i, rc;
+    int i;
 
     for (i = 0; i < readLocks; i++)
        if (readLock[i].fd == fd) {