2 * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
4 * $Id: fileSize.c,v 1.7 2001/04/02 16:10:32 rrt 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 #if defined( macosx_TARGET_OS )
42 *(W_ *) result = (W_)sb.st_size;
44 *(off_t *) result = sb.st_size;
48 ghc_errtype = ERR_INAPPROPRIATETYPE;
49 ghc_errstr = "not a regular file";
55 fileSize_int64(StgForeignPtr ptr, StgByteArray result)
57 IOFileObject* fo = (IOFileObject*)ptr;
61 /* Flush buffer in order to get as an accurate size as poss. */
63 if (rc < 0) return rc;
65 while (fstat(fo->fd, &sb) < 0) {
73 if (S_ISREG(sb.st_mode)) {
74 /* result will be word aligned */
75 *(StgInt64*) result = (StgInt64)sb.st_size;
78 ghc_errtype = ERR_INAPPROPRIATETYPE;
79 ghc_errstr = "not a regular file";