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