Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / signal / psignal.c
blobf847ab2c82a71be66b9ebe05935ad8d1a85dfc69
1 /* Copyright 2002, 2011 Red Hat Inc. */
2 /*
3 FUNCTION
4 <<psignal>>---print a signal message on standard error
6 INDEX
7 psignal
9 SYNOPSIS
10 #include <stdio.h>
11 void psignal(int <[signal]>, const char *<[prefix]>);
13 DESCRIPTION
14 Use <<psignal>> to print (on standard error) a signal message
15 corresponding to the value of the signal number <[signal]>.
16 Unless you use <<NULL>> as the value of the argument <[prefix]>, the
17 signal message will begin with the string at <[prefix]>, followed by a
18 colon and a space (<<: >>). The remainder of the signal message is one
19 of the strings described for <<strsignal>>.
21 RETURNS
22 <<psignal>> returns no result.
24 PORTABILITY
25 POSIX.1-2008 requires <<psignal>>, but the strings issued vary from one
26 implementation to another.
28 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
29 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
32 #include <_ansi.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <unistd.h>
37 #define WRITE_STR(str) \
38 { \
39 const char *p = (str); \
40 size_t len = strlen (p); \
41 while (len) \
42 { \
43 ssize_t len1 = write (fileno (stderr), p, len); \
44 if (len1 < 0) \
45 break; \
46 len -= len1; \
47 p += len1; \
48 } \
51 void
52 psignal (int sig,
53 const char *s)
55 fflush (stderr);
56 if (s != NULL && *s != '\0')
58 WRITE_STR (s);
59 WRITE_STR (": ");
61 WRITE_STR (strsignal (sig));
63 #ifdef __SCLE
64 WRITE_STR ((stderr->_flags & __SCLE) ? "\r\n" : "\n");
65 #else
66 WRITE_STR ("\n");
67 #endif