1PERROR(3)                      Library functions                     PERROR(3)
2
3
4

NAME

6       perror - print a system error message
7

SYNOPSIS

9       #include <stdio.h>
10
11       void perror(const char *s);
12
13       #include <errno.h>
14
15       const char *sys_errlist[];
16       int sys_nerr;
17       int errno;
18

DESCRIPTION

20       The  routine  perror() produces a message on the standard error output,
21       describing the last error encountered during a  call  to  a  system  or
22       library  function.   First  (if s is not NULL and *s is not a null byte
23       ('\0')) the argument string s is printed, followed by  a  colon  and  a
24       blank.  Then the message and a new-line.
25
26       To  be  of most use, the argument string should include the name of the
27       function that incurred the error.  The error number is taken  from  the
28       external variable errno, which is set when errors occur but not cleared
29       when non-erroneous calls are made.
30
31       The global error list sys_errlist[] indexed by errno  can  be  used  to
32       obtain the error message without the newline.  The largest message num‐
33       ber provided in the table is sys_nerr -1.   Be  careful  when  directly
34       accessing this list because new error values may not have been added to
35       sys_errlist[].
36
37       When a system call fails, it usually returns -1 and sets  the  variable
38       errno to a value describing what went wrong. (These values can be found
39       in <errno.h>.)  Many library functions do likewise.  The function  per‐
40       ror()  serves  to  translate  this error code into human-readable form.
41       Note that errno is undefined after a successful library call: this call
42       may  well  change  this  variable, even though it succeeds, for example
43       because it internally used some other  library  function  that  failed.
44       Thus,  if  a failing call is not immediately followed by a call to per‐
45       ror(), the value of errno should be saved.
46
47

CONFORMING TO

49       The function perror() and the external errno (see errno(3)) conform  to
50       C89, C99, 4.3BSD, POSIX.1-2001.  The externals sys_nerr and sys_errlist
51       conform to BSD.
52

NOTE

54       The externals sys_nerr and sys_errlist are defined  by  glibc,  but  in
55       <stdio.h>.
56

SEE ALSO

58       err(3), errno(3), error(3), strerror(3)
59
60
61
62                                  2001-12-14                         PERROR(3)
Impressum