[project @ 1998-11-26 09:17:22 by sof]
[ghc-hetmet.git] / ghc / lib / std / cbits / writeError.lc
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1998
3 %
4
5 Writing out error messages. This is done outside Haskell
6 (i.e., no use of the IO implementation is made), since it
7 might be in an unstable state (e.g., hClose stderr >> error "foo")
8
9 (A secondary reason is that ``error'' is used by the IO
10 implementation in one or two places.)
11
12 \begin{code}
13
14 #include "rtsdefs.h"
15 #include "stgio.h"
16
17 void
18 writeErrString__ (msg_hdr, msg, len)
19 StgAddr msg_hdr;
20 StgByteArray msg;
21 StgInt len;
22 {
23   int count = 0;
24   char* p  = (char*)msg;
25   char  nl = '\n';
26
27   /* Print error msg header */
28   ((void (*)(int))msg_hdr)(2/*stderr*/);
29
30   while ( (count = write(2,p,len)) < len) {
31      if (errno != EINTR ) {
32         return;
33      }
34      len -= count;
35      p   += count;
36   }
37   write(2, &nl, 1);
38 }
39
40 \end{code}