source: trunk/libs/newlib/src/newlib/libc/stdio/perror.c @ 567

Last change on this file since 567 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.3 KB
Line 
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/*
19FUNCTION
20<<perror>>---print an error message on standard error
21
22INDEX
23        perror
24INDEX
25        _perror_r
26
27SYNOPSIS
28        #include <stdio.h>
29        void perror(char *<[prefix]>);
30
31        void _perror_r(struct _reent *<[reent]>, char *<[prefix]>);
32
33DESCRIPTION
34Use <<perror>> to print (on standard error) an error message
35corresponding to the current value of the global variable <<errno>>.
36Unless you use <<NULL>> as the value of the argument <[prefix]>, the
37error message will begin with the string at <[prefix]>, followed by a
38colon and a space (<<: >>). The remainder of the error message is one
39of the strings described for <<strerror>>.
40
41The alternate function <<_perror_r>> is a reentrant version.  The
42extra argument <[reent]> is a pointer to a reentrancy structure.
43
44RETURNS
45<<perror>> returns no result.
46
47PORTABILITY
48ANSI C requires <<perror>>, but the strings issued vary from one
49implementation to another.
50
51Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
52<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
53*/
54
55#include <_ansi.h>
56#include <reent.h>
57#include <stdio.h>
58#include <string.h>
59#include "local.h"
60
61void
62_perror_r (struct _reent *ptr,
63       const char *s)
64{
65  char *error;
66  int dummy;
67
68  _REENT_SMALL_CHECK_INIT (ptr);
69  if (s != NULL && *s != '\0')
70    {
71      fputs (s, _stderr_r (ptr));
72      fputs (": ", _stderr_r (ptr));
73    }
74
75  if ((error = _strerror_r (ptr, ptr->_errno, 1, &dummy)) != NULL)
76    fputs (error, _stderr_r (ptr));
77
78  fputc ('\n', _stderr_r (ptr));
79}
80
81#ifndef _REENT_ONLY
82
83void
84perror (const char *s)
85{
86  _perror_r (_REENT, s);
87}
88
89#endif
Note: See TracBrowser for help on using the repository browser.