1PERROR(3)                  Linux Programmer's Manual                 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
19   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21       sys_errlist, sys_nerr: _BSD_SOURCE
22

DESCRIPTION

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

CONFORMING TO

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

NOTES

57       The externals sys_nerr and sys_errlist are defined  by  glibc,  but  in
58       <stdio.h>.
59

SEE ALSO

61       err(3), errno(3), error(3), strerror(3)
62

COLOPHON

64       This  page  is  part of release 3.25 of the Linux man-pages project.  A
65       description of the project, and information about reporting  bugs,  can
66       be found at http://www.kernel.org/doc/man-pages/.
67
68
69
70                                  2007-07-26                         PERROR(3)
Impressum