perror.c 984 B

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