/contrib/groff/src/libs/libgroff/strerror.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 48 lines · 24 code · 5 blank · 19 comment · 5 complexity · bce52069b0a3ee88bc2a9530ecffa5e8 MD5 · raw file

  1. /* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2003
  2. Free Software Foundation, Inc.
  3. Written by James Clark (jjc@jclark.com)
  4. This file is part of groff.
  5. groff is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 2, or (at your option) any later
  8. version.
  9. groff is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License along
  14. with groff; see the file COPYING. If not, write to the Free Software
  15. Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
  16. #ifdef HAVE_CONFIG_H
  17. #include <config.h>
  18. #endif
  19. #include <stdio.h>
  20. #include <errno.h>
  21. #include <stdlib.h> /* for MinGW */
  22. #define INT_DIGITS 19 /* enough for 64 bit integer */
  23. #ifndef HAVE_SYS_NERR
  24. extern int sys_nerr;
  25. #endif
  26. #ifndef HAVE_SYS_ERRLIST
  27. extern char *sys_errlist[];
  28. #endif
  29. char *strerror(n)
  30. int n;
  31. {
  32. static char buf[sizeof("Error ") + 1 + INT_DIGITS];
  33. if (n >= 0 && n < sys_nerr && sys_errlist[n] != 0)
  34. return sys_errlist[n];
  35. else {
  36. sprintf(buf, "Error %d", n);
  37. return buf;
  38. }
  39. }