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           Since glibc 2.19:
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

ATTRIBUTES

57       For   an   explanation   of   the  terms  used  in  this  section,  see
58       attributes(7).
59
60       ┌──────────┬───────────────┬─────────────────────┐
61Interface Attribute     Value               
62       ├──────────┼───────────────┼─────────────────────┤
63perror()  │ Thread safety │ MT-Safe race:stderr │
64       └──────────┴───────────────┴─────────────────────┘
65

CONFORMING TO

67       perror(), errno: POSIX.1-2001, POSIX.1-2008, C89, C99, 4.3BSD.
68
69       The externals sys_nerr and sys_errlist derive from  BSD,  but  are  not
70       specified in POSIX.1.
71

NOTES

73       The  externals  sys_nerr  and  sys_errlist are defined by glibc, but in
74       <stdio.h>.
75

SEE ALSO

77       err(3), errno(3), error(3), strerror(3)
78

COLOPHON

80       This page is part of release 5.02 of the Linux  man-pages  project.   A
81       description  of  the project, information about reporting bugs, and the
82       latest    version    of    this    page,    can     be     found     at
83       https://www.kernel.org/doc/man-pages/.
84
85
86
87                                  2019-03-06                         PERROR(3)
Impressum