/*
* (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
*
- * $Id: closeFile.c,v 1.7 1999/11/25 16:54:14 simonmar Exp $
+ * $Id: closeFile.c,v 1.10 2000/09/25 10:48:50 simonmar Exp $
*
* hClose Runtime Support
*/
#include "Rts.h"
#include "stgio.h"
+#include <errno.h>
#if defined(HAVE_WINSOCK_H) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
#define USE_WINSOCK
return 0;
}
- if ( flush_buf != 0 && (fo->flags & FILEOBJ_WRITE) ) {
- writeFileObject(ptr,fo->bufWPtr);
+ /* Flush buffer if we have unwritten data */
+ if ( flush_buf != 0 ) {
+ flushBuffer(fo);
}
/* If the flush failed, we ignore this and soldier on.. */
}
+ /* Free the buffer straight away. We can't free the file object
+ * itself until the finalizer runs.
+ */
+ if ( fo->buf != NULL ) {
+ free(fo->buf);
+ fo->buf = NULL;
+ }
+
/* Closing file descriptors that refer to standard channels
is problematic, so we back off from doing this by default,
just closing them at the Handle level. If you insist on
}
}
}
+
fo->fd = -1;
+
return 0;
}