psignal.c 885 B

123456789101112131415161718192021222324252627282930
  1. /*
  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. #include <features.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. extern char *__strsignal (int __sig) __THROW attribute_hidden;
  11. /* TODO: make this threadsafe with a reentrant version of strsignal? */
  12. void psignal(int signum, register const char *message)
  13. {
  14. /* If the program is calling psignal, it's a safe bet that printf and
  15. * friends are used as well. It is also possible that the calling
  16. * program could buffer stderr, or reassign it. */
  17. register const char *sep;
  18. sep = ": ";
  19. if (!(message && *message)) { /* Caller did not supply a prefix message */
  20. message = (sep += 2); /* or passed an empty string. */
  21. }
  22. fprintf(stderr, "%s%s%s\n", message, sep, __strsignal(signum));
  23. }