home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / libio-4.6.26 / ioperror.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-10  |  2.4 KB  |  96 lines

  1. /* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <ansidecl.h>
  20.  
  21. #include "libioP.h"
  22. #include <errno.h>
  23. #ifndef errno
  24. extern int errno;
  25. #endif
  26.  
  27. #if NLS
  28. #include "nl_types.h"
  29. #endif
  30.  
  31. /* Also glibc? */
  32. #ifdef __linux__
  33.  
  34. /* Print a line on stderr consisting of the text in S, a colon, a space,
  35.    a message describing the meaning of the contents of `errno' and a newline.
  36.    If S is NULL or "", the colon and space are omitted.  */
  37. void
  38. DEFUN(_IO_perror, (s), register CONST char *s)
  39. {
  40.   int errnum = errno;
  41.   CONST char *colon;
  42.  
  43. #if NLS
  44.     libc_nls_init();
  45. #endif
  46.   if (s == NULL || *s == '\0')
  47.     s = colon = "";
  48.   else
  49.     colon = ": ";
  50.  
  51.   if (errnum >= 0 && errnum < _sys_nerr)
  52. #if NLS
  53.     (void) _IO_fprintf(_IO_stderr, "%s%s%s\n", s, colon,
  54.        catgets(_libc_cat, ErrorListSet, errnum +1, (char *) _sys_errlist[errnum]));
  55. #else
  56.     (void) _IO_fprintf(_IO_stderr, "%s%s%s\n", s, colon, _sys_errlist[errnum]);
  57. #endif
  58.   else
  59. #if NLS
  60.     (void) _IO_fprintf(_IO_stderr, "%s%s%s %d\n", s, colon,
  61.            catgets(_libc_cat, ErrorListSet, 1,  "Unknown error"),
  62.            errnum);
  63. #else
  64.     (void) _IO_fprintf(_IO_stderr, "%s%sUnknown error %d\n", s, colon, errnum);
  65. #endif
  66. }
  67.  
  68. #else
  69.  
  70. #include <string.h>
  71.  
  72. #ifndef _IO_strerror
  73. extern char* _IO_strerror __P((int));
  74. #endif
  75.  
  76. void
  77. _IO_perror (s)
  78.      const char *s;
  79. {
  80.   char *error = _IO_strerror (errno);
  81.  
  82.   if (s != NULL && *s != '\0')
  83.     _IO_fprintf (_IO_stderr, "%s:", s);
  84.  
  85.   _IO_fprintf (_IO_stderr, "%s\n", error ? error : "");
  86.  
  87. }
  88. #endif
  89.  
  90. #if defined(__ELF__) || defined(__GNU_LIBRARY__)
  91. #include <gnu-stabs.h>
  92. #ifdef weak_alias
  93. weak_alias (_IO_perror, perror);
  94. #endif
  95. #endif
  96.