[project @ 2002-02-12 11:44:54 by simonmar]
[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.9 2001/11/07 18:26:27 sof 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 "HsStd.h"
22
23 #include "PrelIOUtils.h"
24
25 void
26 writeErrString__(HsAddr msg_hdr, HsAddr msg, HsInt len)
27 {
28   int count = 0;
29   char* p  = (char*)msg;
30   char  nl = '\n';
31
32 #ifndef DLLized
33   resetNonBlockingFd(2);
34 #endif
35
36   /* Print error msg header */
37   if (msg_hdr) {
38     ((void (*)(int))msg_hdr)(2/*stderr*/);
39   }
40
41   while ( (count = write(2,p,len)) < len) {
42      if (errno != EINTR ) {
43         return;
44      }
45      len -= count;
46      p   += count;
47   }
48   write(2, &nl, 1);
49 }