2011-05-04 19:26:22 +08:00
|
|
|
/* Copyright 2002, 2011 Red Hat Inc. */
|
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
<<psignal>>---print a signal message on standard error
|
|
|
|
|
|
|
|
INDEX
|
|
|
|
psignal
|
|
|
|
|
2017-11-30 15:43:14 +08:00
|
|
|
SYNOPSIS
|
2011-05-04 19:26:22 +08:00
|
|
|
#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>
|
2018-07-05 22:01:26 +08:00
|
|
|
#include <unistd.h>
|
2018-07-03 17:04:31 +08:00
|
|
|
|
2018-07-05 22:01:26 +08:00
|
|
|
#define WRITE_STR(str) \
|
2018-07-03 17:04:31 +08:00
|
|
|
{ \
|
2018-07-05 22:01:26 +08:00
|
|
|
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; \
|
|
|
|
} \
|
2018-07-03 17:04:31 +08:00
|
|
|
}
|
2011-05-04 19:26:22 +08:00
|
|
|
|
2017-12-04 11:12:33 +08:00
|
|
|
void
|
2017-12-04 11:43:30 +08:00
|
|
|
psignal (int sig,
|
2017-12-04 10:25:16 +08:00
|
|
|
const char *s)
|
2011-05-04 19:26:22 +08:00
|
|
|
{
|
2018-07-05 22:01:26 +08:00
|
|
|
fflush (stderr);
|
2011-05-04 19:26:22 +08:00
|
|
|
if (s != NULL && *s != '\0')
|
2018-07-03 17:04:31 +08:00
|
|
|
{
|
2018-07-05 22:01:26 +08:00
|
|
|
WRITE_STR (s);
|
|
|
|
WRITE_STR (": ");
|
2018-07-03 17:04:31 +08:00
|
|
|
}
|
2018-07-05 22:01:26 +08:00
|
|
|
WRITE_STR (strsignal (sig));
|
2018-07-03 17:04:31 +08:00
|
|
|
|
|
|
|
#ifdef __SCLE
|
2018-07-05 22:01:26 +08:00
|
|
|
WRITE_STR ((stderr->_flags & __SCLE) ? "\r\n" : "\n");
|
2018-07-03 17:04:31 +08:00
|
|
|
#else
|
2018-07-05 22:01:26 +08:00
|
|
|
WRITE_STR ("\n");
|
2018-07-03 17:04:31 +08:00
|
|
|
#endif
|
2011-05-04 19:26:22 +08:00
|
|
|
}
|