[project @ 1999-09-19 19:27:10 by sof]
[ghc-hetmet.git] / ghc / lib / std / cbits / setBinaryMode.c
1 /* 
2  * (c) The GRASP/AQUA Project, Glasgow University, 1999
3  *
4  * $Id: setBinaryMode.c,v 1.1 1999/09/19 19:27:10 sof Exp $
5  *
6  * hSetBinaryMode runtime support
7  */
8
9 #include "Rts.h"
10 #include "stgio.h"
11
12 #ifdef HAVE_FCNTL_H
13 #include <fcntl.h>
14 #endif
15
16 #ifdef _WIN32
17 #include <io.h>
18 #endif
19
20 StgInt
21 setBinaryMode__(ptr,flg)
22 StgForeignPtr ptr;
23 StgInt flg;
24 {
25   IOFileObject* fo = (IOFileObject*)ptr;
26   int rc;
27
28   rc = flushBuffer(ptr);
29   if (rc < 0) return rc;
30
31 #ifdef _WIN32
32   setmode ( fo->fd, flg ? O_BINARY : O_TEXT );
33 #endif
34   rc = (fo->flags & FILEOBJ_BINARY ? 1 : 0);
35   fo->flags = fo->flags & (flg ? FILEOBJ_BINARY : ~FILEOBJ_BINARY);
36
37   return rc;
38 }