summaryrefslogtreecommitdiff
path: root/ghc/lib/std/cbits/writeFile.c
diff options
context:
space:
mode:
authorsimonm <unknown>1998-04-10 10:55:01 +0000
committersimonm <unknown>1998-04-10 10:55:01 +0000
commit3f9b5688990aa7c1170c8d995df69087b43dabeb (patch)
tree98ea8a0869cdea0562c94cfb68398ce451046176 /ghc/lib/std/cbits/writeFile.c
parent1be6e009f6493080ea5d26cdc611279244163db1 (diff)
downloadhaskell-3f9b5688990aa7c1170c8d995df69087b43dabeb.tar.gz
[project @ 1998-04-10 10:54:14 by simonm]
New Run-Time System Support, includes: - New code generator - Modifications to the mangler - Unboxed Tuple support - Various other minor changes.
Diffstat (limited to 'ghc/lib/std/cbits/writeFile.c')
-rw-r--r--ghc/lib/std/cbits/writeFile.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/ghc/lib/std/cbits/writeFile.c b/ghc/lib/std/cbits/writeFile.c
new file mode 100644
index 0000000000..65e1f95b7e
--- /dev/null
+++ b/ghc/lib/std/cbits/writeFile.c
@@ -0,0 +1,59 @@
+/*
+ * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
+ *
+ * $Id: writeFile.c,v 1.1 1998/04/10 10:55:00 simonm Exp $
+ *
+ * hPutStr Runtime Support
+ */
+
+#include "Rts.h"
+#include "stgio.h"
+
+StgInt
+writeFile(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;
+}
+
+
+StgInt
+writeBuf(StgAddr fp, W_ elt_sz, I_ 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;
+}