751a48f11430bc23abedcc2f143bfedcb67d101e
[ghc-hetmet.git] / ghc / lib / std / cbits / freeFile.c
1 /* 
2  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
3  *
4  * $Id: freeFile.c,v 1.1 1998/04/10 10:54:31 simonm Exp $
5  *
6  * Giving up files
7  */
8
9 #include "Rts.h"
10 #include "stgio.h"
11
12 /* sigh, the FILEs attached to the standard descriptors are 
13    handled differently. We don't want them freed via the
14    ForeignObj finaliser, as we probably want to use these
15    before we *really* shut down (dumping stats etc.)
16 */
17 void freeStdFile(StgAddr fp)
18 { return; }
19
20 void freeFile(StgAddr fp)
21 {
22     int rc;
23
24     if ( fp == NULL || (rc = unlockFile(fileno((FILE *)fp))) ) {
25         /* If the file handle has been explicitly closed
26          * (via closeFile()) or freed, we will have given
27          * up our process lock, so we silently return here.
28          */
29        return;
30     }
31
32     /*
33      * The finaliser for the FILEs embedded in Handles. The RTS
34      * assumes that the finaliser runs without problems, so all
35      * we can do here is fclose(), and hope nothing went wrong.
36      *
37      * Assume fclose() flushes output stream.
38      */
39
40     rc = fclose((FILE *)fp);
41     /* Error or no error, we don't care.. */
42
43     /* 
44     if ( rc == EOF ) {
45        fprintf(stderr. "Warning: file close ran into trouble\n");
46     }
47     */
48
49     return;
50 }