-/*
- * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
+/*
+ * (c) The GRASP/AQUA Project, Glasgow University, 1994-2004
*
- * $Id: lockFile.c,v 1.1 2001/06/28 14:15:04 simonmar Exp $
+ * $Id: lockFile.c,v 1.5 2005/01/28 13:36:32 simonmar Exp $
*
* stdin/stout/stderr Runtime Support
*/
-#include "HsCore.h"
+#ifndef mingw32_HOST_OS
-#ifndef FD_SETSIZE
-#define FD_SETSIZE 256
-#endif
+#include "HsBase.h"
+#include "Rts.h"
+#include "RtsUtils.h"
typedef struct {
dev_t device;
struct stat sb;
int i;
+ if (fd > FD_SETSIZE) {
+ barf("lockFile: fd out of range");
+ }
+
while (fstat(fd, &sb) < 0) {
- if (errno != EINTR) {
-#ifndef _WIN32
+ if (errno != EINTR)
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
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__
+ if (readLock[i].inode == sb.st_ino && readLock[i].device == sb.st_dev)
return -1;
-#else
- break;
-#endif
- }
}
/* If we're determined that there is only a single
writer to the file, check to see whether the file
if (exclusive) {
for (i = 0; i < writeLocks; i++) {
if (writeLock[i].inode == sb.st_ino && writeLock[i].device == sb.st_dev) {
-#ifndef __MINGW32__
return -1;
-#else
- break;
-#endif
}
}
}
writeLock[i].inode = sb.st_ino;
writeLock[i].fd = fd;
return 0;
- } else {
+ } else {
/* For reading, it's simpler - just check to see
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) {
-#ifndef __MINGW32__
+ if (writeLock[i].inode == sb.st_ino && writeLock[i].device == sb.st_dev)
return -1;
-#else
- break;
-#endif
- }
}
/* Fit in new entry, reusing an existing table entry, if possible. */
for (i = 0; i < readLocks; i++) {
/* Signal that we did not find an entry */
return 1;
}
+
+#endif