2 * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
4 * $Id: freeFile.c,v 1.3 1998/12/02 13:27:34 simonm Exp $
11 #include "fileObject.h"
13 /* sigh, the FILEs attached to the standard descriptors are
14 handled differently. We don't want them freed via the
15 ForeignObj finaliser, as we probably want to use these
16 before we *really* shut down (dumping stats etc.)
22 void freeStdFileObject(ptr)
25 IOFileObject* fo = (IOFileObject*)ptr;
27 /* Don't close the file, just flush the buffer */
28 if (fo != NULL && fo->fd != -1) {
29 if (fo->buf != NULL && (fo->flags & FILEOBJ_FLUSH) && fo->bufWPtr > 0) {
30 /* Flush buffer contents */
31 writeBuffer((StgForeignPtr)fo, fo->bufWPtr);
36 void freeFileObject(ptr)
40 * The finaliser for the file objects embedded in Handles. The RTS
41 * assumes that the finaliser runs without problems, so all
42 * we can do here is flish buffers + close(), and hope nothing went wrong.
47 IOFileObject* fo = (IOFileObject*)ptr;
52 if ( fo->fd == -1 || (rc = unlockFile(fo->fd)) ) {
53 /* If the file handle has been explicitly closed
54 * (via closeFile()), we will have given
55 * up our process lock, so we break off and just return.
60 if (fo->buf != NULL && fo->bufWPtr > 0) {
61 /* Flush buffer contents before closing underlying file */
62 fo->flags &= ~FILEOBJ_RW_WRITE | ~FILEOBJ_RW_READ;
67 /* Error or no error, we don't care.. */
72 StgAddr ref_freeStdFileObject(void)
74 return (StgAddr)&freeStdFileObject;
77 StgAddr ref_freeFileObject(void)
79 return (StgAddr)&freeFileObject;