1perror(3)                  Library Functions Manual                  perror(3)
2
3
4

NAME

6       perror - print a system error message
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <stdio.h>
13
14       void perror(const char *s);
15
16       #include <errno.h>
17
18       int errno;       /* Not really declared this way; see errno(3) */
19
20       [[deprecated]] const char *const sys_errlist[];
21       [[deprecated]] int sys_nerr;
22
23   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
24
25       sys_errlist, sys_nerr:
26           From glibc 2.19 to glibc 2.31:
27               _DEFAULT_SOURCE
28           glibc 2.19 and earlier:
29               _BSD_SOURCE
30

DESCRIPTION

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

STANDARDS

71       errno
72       perror()
73              C11, POSIX.1-2008.
74
75       sys_nerr
76       sys_errlist
77              BSD.
78

HISTORY

80       errno
81       perror()
82              POSIX.1-2001, C89, 4.3BSD.
83
84       sys_nerr
85       sys_errlist
86              Removed in glibc 2.32.
87

SEE ALSO

89       err(3), errno(3), error(3), strerror(3)
90
91
92
93Linux man-pages 6.05              2023-07-20                         perror(3)
Impressum