Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. /*
  19. FUNCTION
  20. <<perror>>---print an error message on standard error
  21.  
  22. INDEX
  23.         perror
  24. INDEX
  25.         _perror_r
  26.  
  27. ANSI_SYNOPSIS
  28.         #include <stdio.h>
  29.         void perror(char *<[prefix]>);
  30.  
  31.         void _perror_r(struct _reent *<[reent]>, char *<[prefix]>);
  32.  
  33. TRAD_SYNOPSIS
  34.         #include <stdio.h>
  35.         void perror(<[prefix]>)
  36.         char *<[prefix]>;
  37.  
  38.         void _perror_r(<[reent]>, <[prefix]>)
  39.         struct _reent *<[reent]>;
  40.         char *<[prefix]>;
  41.  
  42. DESCRIPTION
  43. Use <<perror>> to print (on standard error) an error message
  44. corresponding to the current value of the global variable <<errno>>.
  45. Unless you use <<NULL>> as the value of the argument <[prefix]>, the
  46. error message will begin with the string at <[prefix]>, followed by a
  47. colon and a space (<<: >>). The remainder of the error message is one
  48. of the strings described for <<strerror>>.
  49.  
  50. The alternate function <<_perror_r>> is a reentrant version.  The
  51. extra argument <[reent]> is a pointer to a reentrancy structure.
  52.  
  53. RETURNS
  54. <<perror>> returns no result.
  55.  
  56. PORTABILITY
  57. ANSI C requires <<perror>>, but the strings issued vary from one
  58. implementation to another.
  59.  
  60. Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
  61. <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
  62. */
  63.  
  64. #include <_ansi.h>
  65. #include <reent.h>
  66. #include <stdio.h>
  67. #include <string.h>
  68. #include "local.h"
  69.  
  70. _VOID
  71. _DEFUN(_perror_r, (ptr, s),
  72.        struct _reent *ptr _AND
  73.        _CONST char *s)
  74. {
  75.   char *error;
  76.   int dummy;
  77.  
  78.   _REENT_SMALL_CHECK_INIT (ptr);
  79.   if (s != NULL && *s != '\0')
  80.     {
  81.       fputs (s, _stderr_r (ptr));
  82.       fputs (": ", _stderr_r (ptr));
  83.     }
  84.  
  85.   if ((error = _strerror_r (ptr, ptr->_errno, 1, &dummy)) != NULL)
  86.     fputs (error, _stderr_r (ptr));
  87.  
  88.   fputc ('\n', _stderr_r (ptr));
  89. }
  90.  
  91. #ifndef _REENT_ONLY
  92.  
  93. _VOID
  94. _DEFUN(perror, (s),
  95.        _CONST char *s)
  96. {
  97.   _perror_r (_REENT, s);
  98. }
  99.  
  100. #endif
  101.