Welcome to mirror list, hosted at ThFree Co, Russian Federation.

psignal.c « signal « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f847ab2c82a71be66b9ebe05935ad8d1a85dfc69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Copyright 2002, 2011 Red Hat Inc. */
/*
FUNCTION
<<psignal>>---print a signal message on standard error

INDEX
	psignal

SYNOPSIS
	#include <stdio.h>
	void psignal(int <[signal]>, const char *<[prefix]>);

DESCRIPTION
Use <<psignal>> to print (on standard error) a signal message
corresponding to the value of the signal number <[signal]>.
Unless you use <<NULL>> as the value of the argument <[prefix]>, the
signal message will begin with the string at <[prefix]>, followed by a
colon and a space (<<: >>). The remainder of the signal message is one
of the strings described for <<strsignal>>.

RETURNS
<<psignal>> returns no result.

PORTABILITY
POSIX.1-2008 requires <<psignal>>, but the strings issued vary from one
implementation to another.

Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/

#include <_ansi.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define WRITE_STR(str) \
{ \
  const char *p = (str); \
  size_t len = strlen (p); \
  while (len) \
    { \
      ssize_t len1 = write (fileno (stderr), p, len); \
      if (len1 < 0) \
	break; \
      len -= len1; \
      p += len1; \
    } \
}

void
psignal (int sig,
       const char *s)
{
  fflush (stderr);
  if (s != NULL && *s != '\0')
    {
      WRITE_STR (s);
      WRITE_STR (": ");
    }
  WRITE_STR (strsignal (sig));

#ifdef __SCLE
  WRITE_STR ((stderr->_flags & __SCLE) ? "\r\n" : "\n");
#else
  WRITE_STR ("\n");
#endif
}