Commit 15ecf716 authored by sof's avatar sof
Browse files

[project @ 1997-03-14 05:17:06 by sof]

FILE objects are now StgForeignPtrs
parent 831045a7
# $Id: Makefile,v 1.2 1996/11/21 16:47:46 simonm Exp $ # $Id: Makefile,v 1.3 1997/03/14 05:17:06 sof Exp $
TOP = ../../.. TOP = ../..
UnlitSuffixRules = YES include $(TOP)/mk/boilerplate.mk
include $(TOP)/ghc/mk/ghc.mk WAYS=
ARCHIVE=libHS_cbits.a LIBRARY=libHS_cbits.a
DESTDIR=$(INSTLIBDIR_GHC) INSTALL_LIBS+=$(LIBRARY)
SRCS=\ SRCS= $(wildcard *.lc)
closeFile.lc createDirectory.lc \
errno.lc fileEOF.lc \ C_SRCS = $(SRCS:.lc=.c)
fileGetc.lc fileLookAhead.lc \ C_OBJS = $(C_SRCS:.c=.o)
filePosn.lc filePutc.lc \ LIBOBJS = $(C_OBJS)
fileSize.lc flushFile.lc \ SRC_CC_OPTS = -I$(GHC_INCLUDE_DIR)
getBufferMode.lc getCurrentDirectory.lc \
getDirectoryContents.lc getLock.lc \ #
inputReady.lc openFile.lc \ # Compile the files using the Haskell compiler (ghc really).
readFile.lc removeDirectory.lc \ #
removeFile.lc renameDirectory.lc \ CC=$(HC)
renameFile.lc seekFile.lc \
setBuffering.lc setCurrentDirectory.lc \ #
system.lc writeFile.lc # Remove the intermediate .c files
# (the .o's will be removed automatically by default mk setup)
LIBOBJS = $(patsubst %.lc, %.o, $(SRCS)) #
CLEAN_FILES += $(C_SRCS)
%.o : %.c
@$(RM) $@ SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
$(GHC) $(GHCFLAGS) -c $< -o $@
include $(TOP)/mk/target.mk
clean ::
$(RM) $(SRCS:.lc=.c)
C_DEP_SRCS = $(SRCS)
MKDEPENDC_OPTS = -I$(GHC_INCLUDES)
include $(TOP)/mk/lib.mk
...@@ -10,11 +10,14 @@ ...@@ -10,11 +10,14 @@
StgInt StgInt
closeFile(fp) closeFile(fp)
StgAddr fp; StgForeignObj fp;
{ {
int rc; int rc;
unlockFile(fileno((FILE *) fp)); if (unlockFile(fileno((FILE *) fp))) {
/* If it has been unlocked, don't bother fclose()ing */
return 0;
}
while ((rc = fclose((FILE *) fp)) != 0) { while ((rc = fclose((FILE *) fp)) != 0) {
if (errno != EINTR) { if (errno != EINTR) {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
StgInt StgInt
fileEOF(fp) fileEOF(fp)
StgAddr fp; StgForeignObj fp;
{ {
if (fileLookAhead(fp) != EOF) if (fileLookAhead(fp) != EOF)
return 0; return 0;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
StgInt StgInt
fileGetc(fp) fileGetc(fp)
StgAddr fp; StgForeignObj fp;
{ {
int c; int c;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
StgInt StgInt
fileLookAhead(fp) fileLookAhead(fp)
StgAddr fp; StgForeignObj fp;
{ {
int c; int c;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
StgInt StgInt
getFilePosn(fp) getFilePosn(fp)
StgAddr fp; StgForeignObj fp;
{ {
StgInt posn; StgInt posn;
...@@ -29,7 +29,7 @@ StgAddr fp; ...@@ -29,7 +29,7 @@ StgAddr fp;
StgInt StgInt
setFilePosn(fp, posn) setFilePosn(fp, posn)
StgAddr fp; StgForeignObj fp;
StgInt posn; StgInt posn;
{ {
while (fseek((FILE *) fp, posn, SEEK_SET) != 0) { while (fseek((FILE *) fp, posn, SEEK_SET) != 0) {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
StgInt StgInt
filePutc(fp, c) filePutc(fp, c)
StgAddr fp; StgForeignObj fp;
StgInt c; StgInt c;
{ {
int rc; int rc;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
StgInt StgInt
fileSize(fp, result) fileSize(fp, result)
StgAddr fp; StgForeignObj fp;
StgByteArray result; StgByteArray result;
{ {
struct stat sb; struct stat sb;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
StgInt StgInt
flushFile(fp) flushFile(fp)
StgAddr fp; StgForeignObj fp;
{ {
int rc; int rc;
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
StgInt StgInt
getBufferMode(fp) getBufferMode(fp)
StgAddr fp; StgForeignObj fp;
{ {
struct stat sb; struct stat sb;
......
...@@ -85,18 +85,18 @@ int exclusive; ...@@ -85,18 +85,18 @@ int exclusive;
return 0; return 0;
} }
void int
unlockFile(fd) unlockFile(fd)
int fd; int fd;
{ {
int i; int i, rc;
for (i = 0; i < readLocks; i++) for (i = 0; i < readLocks; i++)
if (readLock[i].fd == fd) { if (readLock[i].fd == fd) {
while (++i < readLocks) while (++i < readLocks)
readLock[i - 1] = readLock[i]; readLock[i - 1] = readLock[i];
readLocks--; readLocks--;
return; return 0;
} }
for (i = 0; i < writeLocks; i++) for (i = 0; i < writeLocks; i++)
...@@ -104,13 +104,15 @@ int fd; ...@@ -104,13 +104,15 @@ int fd;
while (++i < writeLocks) while (++i < writeLocks)
writeLock[i - 1] = writeLock[i]; writeLock[i - 1] = writeLock[i];
writeLocks--; writeLocks--;
return; return 0;
} }
/* Signal that we did not find an entry */
return 1;
} }
StgInt StgInt
getLock(fp, exclusive) getLock(fp, exclusive)
StgAddr fp; StgForeignObj fp;
StgInt exclusive; StgInt exclusive;
{ {
if (lockFile(fileno((FILE *) fp), exclusive) < 0) { if (lockFile(fileno((FILE *) fp), exclusive) < 0) {
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
StgInt StgInt
inputReady(fp) inputReady(fp)
StgAddr fp; StgForeignObj fp;
{ {
int flags; int flags;
int c; int c;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
StgInt StgInt
readBlock(buf, fp, size) readBlock(buf, fp, size)
StgAddr buf; StgAddr buf;
StgAddr fp; StgForeignObj fp;
StgInt size; StgInt size;
{ {
int count; int count;
...@@ -43,7 +43,7 @@ StgInt size; ...@@ -43,7 +43,7 @@ StgInt size;
StgInt StgInt
readLine(buf, fp, size) readLine(buf, fp, size)
StgAddr buf; StgAddr buf;
StgAddr fp; StgForeignObj fp;
StgInt size; StgInt size;
{ {
if (feof((FILE *) fp)) { if (feof((FILE *) fp)) {
...@@ -70,7 +70,7 @@ StgInt size; ...@@ -70,7 +70,7 @@ StgInt size;
StgInt StgInt
readChar(fp) readChar(fp)
StgAddr fp; StgForeignObj fp;
{ {
int c; int c;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
StgInt StgInt
seekFile(fp, whence, size, d) seekFile(fp, whence, size, d)
StgAddr fp; StgForeignObj fp;
StgInt whence; StgInt whence;
StgInt size; StgInt size;
StgByteArray d; StgByteArray d;
...@@ -106,7 +106,7 @@ StgByteArray d; ...@@ -106,7 +106,7 @@ StgByteArray d;
StgInt StgInt
seekFileP(fp) seekFileP(fp)
StgAddr fp; StgForeignObj fp;
{ {
struct stat sb; struct stat sb;
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
StgInt StgInt
setBuffering(fp, size) setBuffering(fp, size)
StgAddr fp; StgForeignObj fp;
StgInt size; StgInt size;
{ {
int flags; int flags;
......
#ifndef STGIO_H #ifndef STGIO_H
#define STGIO_H #define STGIO_H
/* Decls for routines in ghc/runtime/io/ only used there. /* Decls for routines in ghc/lib/cbits/ only used there.
* This file is used when compiling the Haskell library * This file is used when compiling the Haskell library
* that _ccalls_ those routines; and when compiling those * that _ccalls_ those routines; and when compiling those
* routines (to check consistency). * routines (to check consistency).
*/ */
/* closeFile.lc */ /* closeFile.lc */
StgInt closeFile PROTO((StgAddr)); StgInt closeFile PROTO((StgForeignObj));
/* createDirectory.lc */ /* createDirectory.lc */
StgInt createDirectory PROTO((StgByteArray)); StgInt createDirectory PROTO((StgByteArray));
...@@ -30,29 +30,28 @@ void stdErrno(STG_NO_ARGS); ...@@ -30,29 +30,28 @@ void stdErrno(STG_NO_ARGS);
int execvpe PROTO((char *, char **, char **)); int execvpe PROTO((char *, char **, char **));
/* fileEOF.lc */ /* fileEOF.lc */
StgInt fileEOF PROTO((StgAddr)); StgInt fileEOF PROTO((StgForeignObj));
/* fileGetc.lc */ /* fileGetc.lc */
StgInt fileGetc PROTO((StgAddr)); StgInt fileGetc PROTO((StgForeignObj));
/* fileLookAhead.lc */ /* fileLookAhead.lc */
StgInt fileLookAhead PROTO((StgAddr)); StgInt fileLookAhead PROTO((StgForeignObj));
/* filePosn.lc */ /* filePosn.lc */
StgInt getFilePosn PROTO((StgAddr)); StgInt getFilePosn PROTO((StgForeignObj));
StgInt setFilePosn PROTO((StgAddr, StgInt)); StgInt setFilePosn PROTO((StgForeignObj, StgInt));
/* filePutc.lc */ /* filePutc.lc */
StgInt filePutc PROTO((StgAddr, StgInt)); StgInt filePutc PROTO((StgForeignObj, StgInt));
/* fileSize.lc */ /* fileSize.lc */
StgInt fileSize PROTO((StgAddr, StgByteArray)); StgInt fileSize PROTO((StgForeignObj, StgByteArray));
/* flushFile.lc */ /* flushFile.lc */
StgInt flushFile PROTO((StgAddr)); StgInt flushFile PROTO((StgForeignObj));
/* getBufferMode.lc */ /* getBufferMode.lc */
StgInt getBufferMode PROTO((StgAddr)); StgInt getBufferMode PROTO((StgForeignObj));
/* getClockTime.lc */ /* getClockTime.lc */
StgInt getClockTime PROTO((StgByteArray, StgByteArray)); StgInt getClockTime PROTO((StgByteArray, StgByteArray));
...@@ -68,19 +67,23 @@ StgAddr getDirectoryContents PROTO((StgByteArray)); ...@@ -68,19 +67,23 @@ StgAddr getDirectoryContents PROTO((StgByteArray));
/* getLock.lc */ /* getLock.lc */
int lockFile PROTO((int, int)); int lockFile PROTO((int, int));
void unlockFile PROTO((int)); int unlockFile PROTO((int));
StgInt getLock PROTO((StgAddr, StgInt)); StgInt getLock PROTO((StgForeignObj, StgInt));
/* inputReady.lc */ /* inputReady.lc */
StgInt inputReady PROTO((StgAddr)); StgInt inputReady PROTO((StgForeignObj));
/* openFile.lc */ /* openFile.lc */
StgAddr openFile PROTO((StgByteArray, StgByteArray)); StgAddr openFile PROTO((StgByteArray, StgByteArray));
/* freeFile.lc */
void freeStdChannel PROTO((StgForeignObj));
void freeFile PROTO((StgForeignObj));
/* readFile.lc */ /* readFile.lc */
StgInt readBlock PROTO((StgAddr, StgAddr, StgInt)); StgInt readBlock PROTO((StgAddr, StgForeignObj, StgInt));
StgInt readLine PROTO((StgAddr, StgAddr, StgInt)); StgInt readLine PROTO((StgAddr, StgForeignObj, StgInt));
StgInt readChar PROTO((StgAddr)); StgInt readChar PROTO((StgForeignObj));
/* removeDirectory.lc */ /* removeDirectory.lc */
StgInt removeDirectory PROTO((StgByteArray)); StgInt removeDirectory PROTO((StgByteArray));
...@@ -95,11 +98,11 @@ StgInt renameDirectory PROTO((StgByteArray, StgByteArray)); ...@@ -95,11 +98,11 @@ StgInt renameDirectory PROTO((StgByteArray, StgByteArray));
StgInt renameFile PROTO((StgByteArray, StgByteArray)); StgInt renameFile PROTO((StgByteArray, StgByteArray));
/* seekFile.lc */ /* seekFile.lc */
StgInt seekFile PROTO((StgAddr, StgInt, StgInt, StgByteArray)); StgInt seekFile PROTO((StgForeignObj, StgInt, StgInt, StgByteArray));
StgInt seekFileP PROTO((StgAddr)); StgInt seekFileP PROTO((StgForeignObj));
/* setBuffering.lc */ /* setBuffering.lc */
StgInt setBuffering PROTO((StgAddr, StgInt)); StgInt setBuffering PROTO((StgForeignObj, StgInt));
/* setCurrentDirectory.lc */ /* setCurrentDirectory.lc */
StgInt setCurrentDirectory PROTO((StgByteArray)); StgInt setCurrentDirectory PROTO((StgByteArray));
...@@ -120,6 +123,6 @@ StgAddr toUTCTime PROTO((StgInt, StgByteArray, StgByteArray)); ...@@ -120,6 +123,6 @@ StgAddr toUTCTime PROTO((StgInt, StgByteArray, StgByteArray));
StgAddr toClockSec PROTO((StgInt, StgInt, StgInt, StgInt, StgInt, StgInt, StgInt, StgByteArray)); StgAddr toClockSec PROTO((StgInt, StgInt, StgInt, StgInt, StgInt, StgInt, StgInt, StgByteArray));
/* writeFile.lc */ /* writeFile.lc */
StgInt writeFile PROTO((StgAddr, StgAddr, StgInt)); StgInt writeFile PROTO((StgAddr, StgForeignObj, StgInt));
#endif /* ! STGIO_H */ #endif /* ! STGIO_H */
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
StgInt StgInt
writeFile(buf, fp, bytes) writeFile(buf, fp, bytes)
StgAddr buf; StgAddr buf;
StgAddr fp; StgForeignObj fp;
StgInt bytes; StgInt bytes;
{ {
int count; int count;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment