[project @ 1996-07-25 20:43:49 by partain]
[ghc-hetmet.git] / ghc / lib / cbits / writeFile.lc
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1994
3 %
4 \subsection[writeFile.lc]{hPutStr Runtime Support}
5
6 \begin{code}
7
8 #include "rtsdefs.h"
9 #include "stgio.h"
10
11 StgInt
12 writeFile(buf, fp, bytes)
13 StgAddr buf;
14 StgAddr fp;
15 StgInt bytes;
16 {
17     int count;
18     char *p = (char *) buf;
19
20     if (bytes == 0)
21         return 0;
22
23     /* Disallow short writes */
24     while ((count = fwrite(p, 1, bytes, (FILE *) fp)) < bytes) {
25         if (errno != EINTR) {
26             cvtErrno();
27             stdErrno();
28             return -1;
29         }
30         bytes -= count;
31         p += count;
32         clearerr((FILE *) fp);
33     }
34
35     return 0;
36 }
37
38 \end{code}