[project @ 1998-04-07 08:23:07 by sof]
[ghc-hetmet.git] / ghc / lib / std / cbits / writeFile.lc
index 71c7b0d..80b946f 100644 (file)
@@ -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}