diff options
| author | simonm <unknown> | 1998-02-02 17:35:59 +0000 |
|---|---|---|
| committer | simonm <unknown> | 1998-02-02 17:35:59 +0000 |
| commit | 28139aea50376444d56f43f0914291348a51a7e7 (patch) | |
| tree | 595c378188638ef16462972c1e7fcdb8409c7f16 /ghc/lib/cbits/getLock.lc | |
| parent | 98a1ebecb6d22d793b1d9f8e1d24ecbb5a2d130f (diff) | |
| download | haskell-28139aea50376444d56f43f0914291348a51a7e7.tar.gz | |
[project @ 1998-02-02 17:27:26 by simonm]
Library re-organisation:
All libraries now live under ghc/lib, which has the following structure:
ghc/lib/std -- all prelude files (libHS.a)
ghc/lib/std/cbits
ghc/lib/exts -- standard Hugs/GHC extensions (libHSexts.a)
-- available with '-fglasgow-exts'
ghc/lib/posix -- POSIX library (libHSposix.a)
ghc/lib/posix/cbits -- available with '-syslib posix'
ghc/lib/misc -- used to be hslibs/ghc (libHSmisc.a)
ghc/lib/misc/cbits -- available with '-syslib misc'
ghc/lib/concurrent -- Concurrent libraries (libHSconc.a)
-- available with '-concurrent'
Also, several non-standard prelude modules had their names changed to begin
with 'Prel' to reduce namespace pollution.
Addr ==> PrelAddr (Addr interface available in 'exts')
ArrBase ==> PrelArr
CCall ==> PrelCCall (CCall interface available in 'exts')
ConcBase ==> PrelConc
GHCerr ==> PrelErr
Foreign ==> PrelForeign (Foreign interface available in 'exts')
GHC ==> PrelGHC
IOHandle ==> PrelHandle
IOBase ==> PrelIOBase
GHCmain ==> PrelMain
STBase ==> PrelST
Unsafe ==> PrelUnsafe
UnsafeST ==> PrelUnsafeST
Diffstat (limited to 'ghc/lib/cbits/getLock.lc')
| -rw-r--r-- | ghc/lib/cbits/getLock.lc | 140 |
1 files changed, 0 insertions, 140 deletions
diff --git a/ghc/lib/cbits/getLock.lc b/ghc/lib/cbits/getLock.lc deleted file mode 100644 index 1ed0dbf7ee..0000000000 --- a/ghc/lib/cbits/getLock.lc +++ /dev/null @@ -1,140 +0,0 @@ -% -% (c) The GRASP/AQUA Project, Glasgow University, 1994 -% -\subsection[getLock.lc]{stdin/stout/stderr Runtime Support} - -\begin{code} - -#include "rtsdefs.h" -#include "stgio.h" - -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif - -#ifdef HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif - -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif - -#ifdef HAVE_FCNTL_H -#include <fcntl.h> -#endif - -#ifndef FD_SETSIZE -#define FD_SETSIZE 256 -#endif - -typedef struct { - dev_t device; - ino_t inode; - int fd; -} Lock; - -static Lock readLock[FD_SETSIZE]; -static Lock writeLock[FD_SETSIZE]; - -static int readLocks = 0; -static int writeLocks = 0; - -int -lockFile(fd, exclusive) -int fd; -int exclusive; -{ - int i; - struct stat sb; - - while (fstat(fd, &sb) < 0) { - if (errno != EINTR) { - return -1; - } - } - - /* Only lock regular files */ - if (!S_ISREG(sb.st_mode)) - return 0; - - for (i = 0; i < writeLocks; i++) - if (writeLock[i].inode == sb.st_ino && writeLock[i].device == sb.st_dev) { - errno = EAGAIN; - return -1; - } - - if (!exclusive) { - i = readLocks++; - readLock[i].device = sb.st_dev; - readLock[i].inode = sb.st_ino; - readLock[i].fd = fd; - return 0; - } - - for (i = 0; i < readLocks; i++) - if (readLock[i].inode == sb.st_ino && readLock[i].device == sb.st_dev) { - errno = EAGAIN; - return -1; - } - - i = writeLocks++; - writeLock[i].device = sb.st_dev; - writeLock[i].inode = sb.st_ino; - writeLock[i].fd = fd; - return 0; -} - -int -unlockFile(fd) -int fd; -{ - int i, rc; - - for (i = 0; i < readLocks; i++) - if (readLock[i].fd == fd) { - while (++i < readLocks) - readLock[i - 1] = readLock[i]; - readLocks--; - return 0; - } - - for (i = 0; i < writeLocks; i++) - if (writeLock[i].fd == fd) { - while (++i < writeLocks) - writeLock[i - 1] = writeLock[i]; - writeLocks--; - return 0; - } - /* Signal that we did not find an entry */ - return 1; -} - -StgInt -getLock(fp, exclusive) -StgForeignObj fp; -StgInt exclusive; -{ - if (lockFile(fileno((FILE *) fp), exclusive) < 0) { - if (errno == EBADF) - return 0; - else { - cvtErrno(); - switch (ghc_errno) { - default: - stdErrno(); - break; - case GHC_EACCES: - case GHC_EAGAIN: - ghc_errtype = ERR_RESOURCEBUSY; - ghc_errstr = "file is locked"; - break; - } - (void) fclose((FILE *) fp); - return -1; - } - } - return 1; -} - -\end{code} |
