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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
%
% (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;
StgForeignObj 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;
}
StgInt
writeBuf(fp, elt_sz, len, buf)
StgForeignObj fp;
StgWord elt_sz;
StgInt len;
StgAddr buf;
{
int count;
char *p = (char *) buf;
if (len == 0 || elt_sz == 0)
return 0;
/* Disallow short writes */
while ((count = fwrite((char *)buf, (unsigned)elt_sz, (int)len, (FILE *) fp)) < len) {
if (errno != EINTR) {
cvtErrno();
stdErrno();
return -1;
}
len -= count;
p += count;
clearerr((FILE *) fp);
}
return 0;
}
\end{code}
|