summaryrefslogtreecommitdiff
path: root/ghc/lib/std/cbits/writeFile.lc
diff options
context:
space:
mode:
authorsof <unknown>1998-04-07 08:23:08 +0000
committersof <unknown>1998-04-07 08:23:08 +0000
commitf3211cf9a67d44e99c44ef81190b9d7b50ef2872 (patch)
tree6f4b38f95b67c684cefb5d3ae5afc087e3ef5874 /ghc/lib/std/cbits/writeFile.lc
parente73a5f4b46a0ef8770eb42a0c2c67e2adf66a6e5 (diff)
downloadhaskell-f3211cf9a67d44e99c44ef81190b9d7b50ef2872.tar.gz
[project @ 1998-04-07 08:23:07 by sof]
new function: writeBuf
Diffstat (limited to 'ghc/lib/std/cbits/writeFile.lc')
-rw-r--r--ghc/lib/std/cbits/writeFile.lc29
1 files changed, 29 insertions, 0 deletions
diff --git a/ghc/lib/std/cbits/writeFile.lc b/ghc/lib/std/cbits/writeFile.lc
index 71c7b0df17..80b946f117 100644
--- a/ghc/lib/std/cbits/writeFile.lc
+++ b/ghc/lib/std/cbits/writeFile.lc
@@ -35,4 +35,33 @@ StgInt bytes;
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}