2 * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
4 * $Id: flushFile.c,v 1.8 2000/09/25 10:51:04 simonmar Exp $
6 * hFlush Runtime Support
13 flushFile(StgForeignPtr ptr)
15 IOFileObject* fo = (IOFileObject*)ptr;
18 if ( FILEOBJ_WRITEABLE(fo) && FILEOBJ_JUST_WRITTEN(fo) &&
19 FILEOBJ_NEEDS_FLUSHING(fo) ) {
20 rc = writeBuffer(ptr, fo->bufWPtr - fo->bufRPtr);
27 flushBuffer(StgForeignPtr ptr)
29 IOFileObject* fo = (IOFileObject*)ptr;
32 if ( FILEOBJ_WRITEABLE(fo) && FILEOBJ_JUST_WRITTEN(fo) &&
33 FILEOBJ_NEEDS_FLUSHING(fo) ) {
34 rc = writeBuffer(ptr, fo->bufWPtr - fo->bufRPtr);
38 /* TODO: shouldn't we do the lseek stuff from flushReadBuffer
42 /* Reset read & write pointer for input buffers */
43 if ( (fo->flags & FILEOBJ_READ) ) {
51 For RW file objects, flushing input buffers doesn't just involve
52 resetting the read & write pointers, we also have to change the
53 underlying file position to point to the effective read position.
55 (Sigh, I now understand the real reason for why stdio opted for
56 the solution of leaving this to the programmer!)
59 flushReadBuffer(StgForeignPtr ptr)
61 IOFileObject* fo = (IOFileObject*)ptr;
64 delta = fo->bufWPtr - fo->bufRPtr;
67 while ( lseek(fo->fd, -delta, SEEK_CUR) == -1) {
82 flushConnectedBuf(StgForeignPtr ptr)
85 IOFileObject* fo = (IOFileObject*)ptr;
87 /* if the stream is connected to an output stream, flush it. */
88 if ( fo->connectedTo != NULL && fo->connectedTo->fd != -1 &&
89 (fo->connectedTo->flags & FILEOBJ_WRITE) ) {
90 rc = flushBuffer((StgForeignPtr)fo->connectedTo);
92 /* Willfully ignore the return code for now. */