perror.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. libc_hidden_proto(fprintf)
  9. libc_hidden_proto(__glibc_strerror_r)
  10. libc_hidden_proto(stderr)
  11. #ifdef __UCLIBC_MJN3_ONLY__
  12. #warning CONSIDER: Increase buffer size for error message (non-%m case)?
  13. #endif
  14. libc_hidden_proto(perror)
  15. void perror(register const char *s)
  16. {
  17. /* If the program is calling perror, it's a safe bet that printf and
  18. * friends are used as well. It is also possible that the calling
  19. * program could buffer stderr, or reassign it. */
  20. register const char *sep;
  21. sep = ": ";
  22. if (!(s && *s)) { /* Caller did not supply a prefix message */
  23. s = (sep += 2); /* or passed an empty string. */
  24. }
  25. #ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
  26. fprintf(stderr, "%s%s%m\n", s, sep); /* Use the gnu %m feature. */
  27. #else
  28. {
  29. char buf[64];
  30. fprintf(stderr, "%s%s%s\n", s, sep,
  31. __glibc_strerror_r(errno, buf, sizeof(buf)));
  32. }
  33. #endif
  34. }
  35. libc_hidden_def(perror)