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