[project @ 1996-06-30 15:56:44 by partain]
[ghc-hetmet.git] / ghc / runtime / io / writeDescriptor.lc
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1996
3 %
4 \subsection[writeDescriptor.lc]{Stuff bytes down a descriptor}
5
6 \begin{code}
7
8 #include "rtsdefs.h"
9 #include "stgio.h"
10
11 StgInt
12 writeDescriptor(int fd, char *buf, int nbytes)
13 {
14     StgInt dumped;
15     
16     while ((dumped = write(fd, buf, nbytes)) < 0) {
17       if (errno != EINTR) {
18           cvtErrno();
19           switch (ghc_errno) {
20           default:
21               stdErrno();
22               break;
23           case GHC_EBADF:
24               ghc_errtype = ERR_INVALIDARGUMENT;
25               ghc_errstr  = "Not a valid write descriptor";
26               break;
27           case GHC_EDQUOT:
28               ghc_errtype = ERR_RESOURCEEXHAUSTED;
29               ghc_errstr  = "Disk quota exhausted";
30               break;
31           case GHC_EFAULT:
32               ghc_errtype = ERR_INVALIDARGUMENT;
33               ghc_errstr  = "Data not in writeable part of user address space";
34               break;
35           case GHC_EFBIG:
36               ghc_errtype = ERR_RESOURCEEXHAUSTED;
37               ghc_errstr  = "Maximum process or system file size exceeded";
38               break;
39           case GHC_EINVAL:
40               ghc_errtype = ERR_INVALIDARGUMENT;
41               ghc_errstr  = "Seek pointer associated with descriptor negative";
42               break;
43           case GHC_EIO:
44               ghc_errtype = ERR_SYSTEMERROR;
45               ghc_errstr  = "I/O error occurred while writing to file system";
46               break;
47           case GHC_ENOSPC:
48               ghc_errtype = ERR_RESOURCEEXHAUSTED;
49               ghc_errstr  = "No space left on device";
50               break;
51           case GHC_ENXIO:
52               ghc_errtype = ERR_SYSTEMERROR;
53               ghc_errstr  = "Hangup occurred";
54               break;
55           case GHC_EPIPE:
56               ghc_errtype = ERR_SYSTEMERROR;
57               ghc_errstr  = "Write to not read pipe/unconnected socket caught";
58               break;
59           case GHC_ERANGE:
60               ghc_errtype = ERR_INVALIDARGUMENT;
61               ghc_errstr  = "Too much or too little written to descriptor";
62               break;
63           case GHC_EAGAIN:
64           case GHC_EWOULDBLOCK:
65               ghc_errtype = ERR_OTHERERROR;
66               ghc_errstr  = "No data could be written immediately";
67               break;
68           }
69           return -1;
70       }
71     }
72     return dumped;
73 }
74
75 \end{code}