summaryrefslogtreecommitdiff
path: root/ghc/lib/misc/cbits/writeDescriptor.c
blob: d6f14d28b55818e02389c547e42aaf0d58e69690 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#if 0
%
% (c) The GRASP/AQUA Project, Glasgow University, 1996
%
\subsection[writeDescriptor.lc]{Stuff bytes down a descriptor}

\begin{code}
#endif

#define NON_POSIX_SOURCE
#include "Rts.h"
#include "ghcSockets.h"
#include "stgio.h"

StgInt
writeDescriptor(I_ fd, A_ buf, I_ nbytes)
{
    StgInt dumped;
    
    while ((dumped = write((int) fd, (char *) buf, (int) 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;
}