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 *const sys_errlist[];
16       int sys_nerr;
17       int errno;       /* Not really declared this way; see errno(3) */
18
19   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21       sys_errlist, sys_nerr:
22           From glibc 2.19 to 2.31:
23               _DEFAULT_SOURCE
24           Glibc 2.19 and earlier:
25               _BSD_SOURCE
26

DESCRIPTION

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

VERSIONS

57       Since  glibc version 2.32, the declarations of sys_errlist and sys_nerr
58       are no longer exposed by <stdio.h>.
59

ATTRIBUTES

61       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
62       tributes(7).
63
64       ┌────────────────────────────────┬───────────────┬─────────────────────┐
65Interface                       Attribute     Value               
66       ├────────────────────────────────┼───────────────┼─────────────────────┤
67perror()                        │ Thread safety │ MT-Safe race:stderr │
68       └────────────────────────────────┴───────────────┴─────────────────────┘
69

CONFORMING TO

71       perror(), errno: POSIX.1-2001, POSIX.1-2008, C89, C99, 4.3BSD.
72
73       The  externals  sys_nerr  and  sys_errlist derive from BSD, but are not
74       specified in POSIX.1.
75

NOTES

77       The externals sys_nerr and sys_errlist are defined  by  glibc,  but  in
78       <stdio.h>.
79

SEE ALSO

81       err(3), errno(3), error(3), strerror(3)
82

COLOPHON

84       This  page  is  part of release 5.13 of the Linux man-pages project.  A
85       description of the project, information about reporting bugs,  and  the
86       latest     version     of     this    page,    can    be    found    at
87       https://www.kernel.org/doc/man-pages/.
88
89
90
91                                  2021-03-22                         PERROR(3)
Impressum