[project @ 1996-06-27 16:13:29 by partain]
[ghc-hetmet.git] / ghc / runtime / io / writeDescriptor.lc
diff --git a/ghc/runtime/io/writeDescriptor.lc b/ghc/runtime/io/writeDescriptor.lc
new file mode 100644 (file)
index 0000000..acab07e
--- /dev/null
@@ -0,0 +1,75 @@
+%
+% (c) The GRASP/AQUA Project, Glasgow University, 1996
+%
+\subsection[writeDescriptor.lc]{Stuff bytes down a descriptor}
+
+\begin{code}
+
+#include "rtsdefs.h"
+#include "stgio.h"
+
+StgInt
+writeDescriptor(int fd, char *buf, int nbytes)
+{
+    StgInt dumped;
+    
+    while ((dumped = write(fd, buf, nbytes)) < 0) {
+      if (errno != EINTR) {
+         cvtErrno();
+         switch (ghc_errno) {
+         default:
+             stdErrno();
+             break;
+         case GHC_EBADF:
+                     ghc_errtype = ERR_INVALIDARGUMENT;
+              ghc_errstr  = "Not a valid write descriptor";
+             break;
+         case GHC_EDQUOT:
+                     ghc_errtype = ERR_RESOURCEEXHAUSTED;
+              ghc_errstr  = "Disk quota exhausted";
+             break;
+         case GHC_EFAULT:
+                     ghc_errtype = ERR_INVALIDARGUMENT;
+              ghc_errstr  = "Data not in writeable part of user address space";
+             break;
+         case GHC_EFBIG:
+             ghc_errtype = ERR_RESOURCEEXHAUSTED;
+             ghc_errstr  = "Maximum process or system file size exceeded";
+             break;
+         case GHC_EINVAL:
+             ghc_errtype = ERR_INVALIDARGUMENT;
+             ghc_errstr  = "Seek pointer associated with descriptor negative";
+             break;
+         case GHC_EIO:
+             ghc_errtype = ERR_SYSTEMERROR;
+             ghc_errstr  = "I/O error occurred while writing to file system";
+             break;
+         case GHC_ENOSPC:
+             ghc_errtype = ERR_RESOURCEEXHAUSTED;
+             ghc_errstr  = "No space left on device";
+             break;
+         case GHC_ENXIO:
+             ghc_errtype = ERR_SYSTEMERROR;
+             ghc_errstr  = "Hangup occurred";
+             break;
+         case GHC_EPIPE:
+             ghc_errtype = ERR_SYSTEMERROR;
+             ghc_errstr  = "Write to not read pipe/unconnected socket caught";
+             break;
+         case GHC_ERANGE:
+             ghc_errtype = ERR_INVALIDARGUMENT;
+             ghc_errstr  = "Too much or too little written to descriptor";
+             break;
+         case GHC_EAGAIN:
+         case GHC_EWOULDBLOCK:
+             ghc_errtype = ERR_OTHERERROR;
+             ghc_errstr  = "No data could be written immediately";
+             break;
+         }
+         return -1;
+      }
+    }
+    return dumped;
+}
+
+\end{code}