[project @ 2005-01-28 16:09:06 by malcolm]
[ghc-base.git] / cbits / writeError.c
1 /*
2  * (c) The University of Glasgow 2002
3  *
4  * $Id: writeError.c,v 1.6 2004/02/12 21:23:49 krasimir 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 "HsBase.h"
22
23 void
24 writeErrString__(HsAddr msg, HsInt len)
25 {
26   int count = 0;
27   char* p  = (char*)msg;
28   char  nl = '\n';
29
30 #ifndef DLLized
31   resetNonBlockingFd(2);
32 #endif
33
34   while ( (count = write(2,p,len)) < len) {
35      if (errno != EINTR ) {
36         return;
37      }
38      len -= count;
39      p   += count;
40   }
41   write(2, &nl, 1);
42 }