[project @ 1996-06-27 16:13:29 by partain]
[ghc-hetmet.git] / ghc / runtime / io / readDescriptor.lc
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1996
3 %
4 \subsection[readDescriptor.lc]{Suck some bytes from a descriptor}
5
6 \begin{code}
7
8 #include "rtsdefs.h"
9 #include "stgio.h"
10
11 StgInt
12 readDescriptor(int fd, char *buf, int nbytes)
13 {
14     StgInt sucked;
15     
16     while ((sucked = read(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_EBADMSG:
28               ghc_errtype = ERR_SYSTEMERROR;
29               ghc_errstr  = "Message waiting to be read is not a data message";
30               break;
31           case GHC_EFAULT:
32               ghc_errtype = ERR_INVALIDARGUMENT;
33               ghc_errstr  = "Data buffer not in writeable part of user address space";
34               break;
35           case GHC_EINVAL:
36               ghc_errtype = ERR_INVALIDARGUMENT;
37               ghc_errstr  = "Seek pointer associated with descriptor negative";
38               break;
39           case GHC_EIO:
40               ghc_errtype = ERR_SYSTEMERROR;
41               ghc_errstr  = "I/O error occurred while writing to file system";
42               break;
43           case GHC_EISDIR:
44               ghc_errtype = ERR_INAPPROPRIATETYPE;
45               ghc_errstr  = "Descriptor refers to a directory";
46               break;
47           case GHC_EAGAIN:
48           case GHC_EWOULDBLOCK:
49               ghc_errtype = ERR_OTHERERROR;
50               ghc_errstr  = "No data could be written immediately";
51               break;
52           }
53           return -1;
54       }
55     }
56     return sucked;
57 }
58
59 \end{code}