perror.c 1.0 KB

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