2 * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
4 * $Id: filePosn.c,v 1.4 1999/09/19 19:20:50 sof Exp $
6 * hGetPosn and hSetPosn Runtime Support
16 IOFileObject* fo = (IOFileObject*)ptr;
19 while ( (posn = lseek(fo->fd, 0, SEEK_CUR)) == -1) {
26 if (fo->flags & FILEOBJ_WRITE) {
28 } else if (fo->flags & FILEOBJ_READ) {
29 posn -= (fo->bufWPtr - fo->bufRPtr);
31 if (!(fo->flags & FILEOBJ_BINARY)) {
32 /* Sigh, to get at the Real file position for files opened
33 in text mode, we need to scan the read buffer looking for
34 '\n's, making them count as \r\n (i.e., undoing the work of
35 read()), since lseek() returns the raw position.
41 if (((char*)fo->buf)[i] == '\n') {
52 /* The following is only called with a position that we've already visited
53 (this is ensured by making the Haskell file posn. type abstract.)
56 setFilePosn(ptr, size, d)
61 IOFileObject* fo = (IOFileObject*)ptr;
66 * We need to snatch the offset out of an MP_INT. The bits are there sans sign,
67 * which we pick up from our size parameter. If abs(size) is greater than 1,
68 * this integer is just too big.
72 offset = -*(StgInt *) d;
78 offset = *(StgInt *) d;
81 ghc_errtype = ERR_INVALIDARGUMENT;
82 ghc_errstr = "offset out of range";
86 rc = flushBuffer(ptr);
87 if (rc < 0) return rc;
89 while (lseek(fo->fd, offset, SEEK_SET) == -1) {
96 FILEOBJ_CLEAR_EOF(fo);