X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Flib%2Fstd%2Fcbits%2FgetBufferMode.lc;h=fc894a71dc1455af2663333dcf177fb4b5606608;hb=967cc47f37cb93a5e2b6df7822c9a646f0428247;hp=cb0b9840d2a25cb502d70f748c6cb5f5ecd208fe;hpb=28139aea50376444d56f43f0914291348a51a7e7;p=ghc-hetmet.git diff --git a/ghc/lib/std/cbits/getBufferMode.lc b/ghc/lib/std/cbits/getBufferMode.lc index cb0b984..fc894a7 100644 --- a/ghc/lib/std/cbits/getBufferMode.lc +++ b/ghc/lib/std/cbits/getBufferMode.lc @@ -27,13 +27,15 @@ #define GBM_ERR (-3) StgInt -getBufferMode(fp) -StgForeignObj fp; +getBufferMode(ptr) +StgForeignObj ptr; { + IOFileObject* fo = (IOFileObject*)ptr; struct stat sb; + int fd = fo->fd; /* Try to find out the file type */ - while (fstat(fileno((FILE *) fp), &sb) < 0) { + while (fstat(fd, &sb) < 0) { /* highly unlikely */ if (errno != EINTR) { cvtErrno(); @@ -42,11 +44,14 @@ StgForeignObj fp; } } /* Terminals are line-buffered by default */ - if (S_ISCHR(sb.st_mode) && isatty(fileno((FILE *) fp)) == 1) + if (S_ISCHR(sb.st_mode) && isatty(fd) == 1) { + fo ->flags |= FILEOBJ_LB; return GBM_LB; /* Default size block buffering for the others */ - else + } else { + fo ->flags |= FILEOBJ_BB; return GBM_BB; + } } \end{code}