blob: 3e1f68b94e9b33e20033f591822c7f4fc38e4f6a [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
2 * Copyright (C) 2002 Manuel Novoa III
3 * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
4 *
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 */
7
8#include <features.h>
9#include <stdio.h>
10#include <string.h>
11#include <signal.h>
12
13
14/* TODO: make this threadsafe with a reentrant version of strsignal? */
15
16void psignal(int signum, register const char *message)
17{
18 /* If the program is calling psignal, it's a safe bet that printf and
19 * friends are used as well. It is also possible that the calling
20 * program could buffer stderr, or reassign it. */
21
22 register const char *sep;
23
24 sep = ": ";
25 if (!(message && *message)) { /* Caller did not supply a prefix message */
26 message = (sep += 2); /* or passed an empty string. */
27 }
28
29 fprintf(stderr, "%s%s%s\n", message, sep, strsignal(signum));
30}