perror.c 874 B

123456789101112131415161718192021222324252627282930313233
  1. /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
  2. *
  3. * GNU Library General Public License (LGPL) version 2 or later.
  4. *
  5. * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
  6. */
  7. #include "_stdio.h"
  8. void perror(register const char *s)
  9. {
  10. /* If the program is calling perror, it's a safe bet that printf and
  11. * friends are used as well. It is also possible that the calling
  12. * program could buffer stderr, or reassign it. */
  13. register const char *sep;
  14. sep = ": ";
  15. if (!(s && *s)) { /* Caller did not supply a prefix message */
  16. s = (sep += 2); /* or passed an empty string. */
  17. }
  18. #ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
  19. fprintf(stderr, "%s%s%m\n", s, sep); /* Use the gnu %m feature. */
  20. #else
  21. {
  22. char buf[64];
  23. fprintf(stderr, "%s%s%s\n", s, sep,
  24. __glibc_strerror_r(errno, buf, sizeof(buf)));
  25. }
  26. #endif
  27. }
  28. libc_hidden_def(perror)