summaryrefslogtreecommitdiff
path: root/ghc/lib/cbits/writeFile.lc
blob: 6981bf128ca2f87291956fa63a5221c48acadd95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
%
% (c) The GRASP/AQUA Project, Glasgow University, 1994
%
\subsection[writeFile.lc]{hPutStr Runtime Support}

\begin{code}

#include "rtsdefs.h"
#include "stgio.h"

StgInt
writeFile(buf, fp, bytes)
StgAddr buf;
StgAddr fp;
StgInt bytes;
{
    int count;
    char *p = (char *) buf;

    if (bytes == 0)
	return 0;

    /* Disallow short writes */
    while ((count = fwrite(p, 1, bytes, (FILE *) fp)) < bytes) {
	if (errno != EINTR) {
	    cvtErrno();
	    stdErrno();
	    return -1;
	}
	bytes -= count;
	p += count;
	clearerr((FILE *) fp);
    }

    return 0;
}

\end{code}