[project @ 2000-05-01 14:44:25 by panne]
[ghc-hetmet.git] / ghc / lib / std / cbits / writeError.c
1 /* 
2  * (c) The GRASP/AQUA Project, Glasgow University, 1998
3  *
4  * $Id: writeError.c,v 1.5 2000/05/01 14:44:25 panne Exp $
5  *
6  * hPutStr Runtime Support
7  */
8
9 /*
10 Writing out error messages. This is done outside Haskell
11 (i.e., no use of the IO implementation is made), since it
12 might be in an unstable state (e.g., hClose stderr >> error "foo")
13
14 (A secondary reason is that ``error'' is used by the IO
15 implementation in one or two places.)
16
17 */
18
19 #include "Rts.h"
20 #include "RtsUtils.h"
21 #include "stgio.h"
22
23 #ifdef HAVE_FCNTL_H
24 #include <fcntl.h>
25 #endif
26
27 StgAddr
28 addrOf_ErrorHdrHook(void)
29 {
30   return &ErrorHdrHook;
31 }
32
33 void
34 writeErrString__ (msg_hdr, msg, len)
35 StgAddr msg_hdr;
36 StgByteArray msg;
37 StgInt len;
38 {
39   int count = 0;
40   char* p  = (char*)msg;
41   char  nl = '\n';
42
43   resetNonBlockingFd(2);
44
45   /* Print error msg header */
46   if (msg_hdr) {
47     ((void (*)(int))msg_hdr)(2/*stderr*/);
48   }
49
50   while ( (count = write(2,p,len)) < len) {
51      if (errno != EINTR ) {
52         return;
53      }
54      len -= count;
55      p   += count;
56   }
57   write(2, &nl, 1);
58 }