2 * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
4 * $Id: fileSize.c,v 1.4 2000/12/11 17:51:57 simonmar Exp $
6 * hClose Runtime Support
12 #ifdef HAVE_SYS_TYPES_H
13 #include <sys/types.h>
16 #ifdef HAVE_SYS_STAT_H
21 fileSize(StgForeignPtr ptr, StgByteArray result)
23 IOFileObject* fo = (IOFileObject*)ptr;
27 /* Flush buffer in order to get as an accurate size as poss. */
29 if (rc < 0) return rc;
31 while (fstat(fo->fd, &sb) < 0) {
39 if (S_ISREG(sb.st_mode)) {
40 /* result will be word aligned */
41 *(off_t *) result = sb.st_size;
44 ghc_errtype = ERR_INAPPROPRIATETYPE;
45 ghc_errstr = "not a regular file";
51 fileSize_int64(StgForeignPtr ptr, StgByteArray result)
53 IOFileObject* fo = (IOFileObject*)ptr;
57 /* Flush buffer in order to get as an accurate size as poss. */
59 if (rc < 0) return rc;
61 while (fstat(fo->fd, &sb) < 0) {
69 if (S_ISREG(sb.st_mode)) {
70 /* result will be word aligned */
71 *(StgInt64*) result = (StgInt64)sb.st_size;
74 ghc_errtype = ERR_INAPPROPRIATETYPE;
75 ghc_errstr = "not a regular file";