summaryrefslogtreecommitdiff
path: root/ghc/lib/std/cbits/writeFile.lc
diff options
context:
space:
mode:
authorsimonm <unknown>1998-04-10 11:35:02 +0000
committersimonm <unknown>1998-04-10 11:35:02 +0000
commita586fca9b8d54f935babca01e1308ac51840f8ae (patch)
tree8ee77a3c66962628c3993e74c375440705542f89 /ghc/lib/std/cbits/writeFile.lc
parent70563d29fba4a76a788d3fdeb09899c5931a52ee (diff)
downloadhaskell-a586fca9b8d54f935babca01e1308ac51840f8ae.tar.gz
[project @ 1998-04-10 11:33:12 by simonm]
clean up the mess.
Diffstat (limited to 'ghc/lib/std/cbits/writeFile.lc')
-rw-r--r--ghc/lib/std/cbits/writeFile.lc67
1 files changed, 67 insertions, 0 deletions
diff --git a/ghc/lib/std/cbits/writeFile.lc b/ghc/lib/std/cbits/writeFile.lc
new file mode 100644
index 0000000000..80b946f117
--- /dev/null
+++ b/ghc/lib/std/cbits/writeFile.lc
@@ -0,0 +1,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}