[project @ 1998-12-02 13:17:09 by simonm]
[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.2 1998/12/02 13:28:05 simonm 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 "stgio.h"
21
22 void
23 writeErrString__ (msg_hdr, msg, len)
24 StgAddr msg_hdr;
25 StgByteArray msg;
26 StgInt len;
27 {
28   int count = 0;
29   char* p  = (char*)msg;
30   char  nl = '\n';
31
32   /* Print error msg header */
33   if (msg_hdr) {
34     ((void (*)(int))msg_hdr)(2/*stderr*/);
35   }
36
37   while ( (count = write(2,p,len)) < len) {
38      if (errno != EINTR ) {
39         return;
40      }
41      len -= count;
42      p   += count;
43   }
44   write(2, &nl, 1);
45 }