[project @ 2001-03-01 12:25:32 by rrt]
[ghc-hetmet.git] / ghc / lib / std / cbits / setBuffering.c
index 2aa451c..6bc943a 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
  *
- * $Id: setBuffering.c,v 1.4 1999/03/01 09:26:45 sof Exp $
+ * $Id: setBuffering.c,v 1.11 2001/03/01 12:25:33 rrt Exp $
  *
  * hSetBuffering Runtime Support
  */
 #define SB_BB (-2)
 
 StgInt
-setBuffering(ptr, size)
-StgForeignPtr ptr;
-StgInt size;
+setBuffering(StgForeignPtr ptr, StgInt size)
 {
     IOFileObject* fo = (IOFileObject*)ptr;
     int flags, rc=0;
     int input, isaterm;
+#ifndef mingw32_TARGET_OS
     struct termios tio;
-    struct stat sb;
-   
+#endif
+    struct Stat sb;
 
     /* First off, flush old buffer.. */
-    if ( (fo->flags & FILEOBJ_FLUSH) ) {
+    if ( (fo->flags & FILEOBJ_WRITE) ) {
        rc = flushBuffer(ptr);
     }
     if (rc<0) return rc;
@@ -85,7 +84,7 @@ StgInt size;
            tio.c_lflag &=  ~ICANON;
            tio.c_cc[VMIN] = 1;
            tio.c_cc[VTIME] = 0;
-           if (tcsetattr(fo->fd, TCSANOW, &tio) < 0) {
+           if (tcSetAttr(fo->fd, TCSANOW, &tio) < 0) {
                cvtErrno();
                stdErrno();
                return -1;
@@ -100,8 +99,8 @@ StgInt size;
        break;
     case SB_BB:
 
-#if HAVE_ST_BLKSIZE
-       while (fstat(fo->fd, &sb) < 0) {
+#ifdef HAVE_ST_BLKSIZE
+       while (Fstat(fo->fd, &sb) < 0) {
           /* not very likely.. */
           if ( errno != EINTR ) {
              cvtErrno();
@@ -124,9 +123,9 @@ StgInt size;
        fo->buf = malloc(size*sizeof(char));
        if (fo->buf == NULL) {
            return -1;
-       }
-       fo->bufSize = size;
+       }  
     }
+    fo->bufSize = size;
 #ifndef mingw32_TARGET_OS
     if (isaterm) {
 
@@ -140,7 +139,7 @@ StgInt size;
            return -1;
        }
        tio.c_lflag |= ICANON;
-       if (tcsetattr(fo->fd, TCSANOW, &tio) < 0) {
+       if (tcSetAttr(fo->fd, TCSANOW, &tio) < 0) {
            cvtErrno();
            stdErrno();
            return -1;