1PERROR(3P) POSIX Programmer's Manual PERROR(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 perror — write error messages to standard error
14
16 #include <stdio.h>
17
18 void perror(const char *s);
19
21 The functionality described on this reference page is aligned with the
22 ISO C standard. Any conflict between the requirements described here
23 and the ISO C standard is unintentional. This volume of POSIX.1‐2008
24 defers to the ISO C standard.
25
26 The perror() function shall map the error number accessed through the
27 symbol errno to a language-dependent error message, which shall be
28 written to the standard error stream as follows:
29
30 * First (if s is not a null pointer and the character pointed to by s
31 is not the null byte), the string pointed to by s followed by a
32 <colon> and a <space>.
33
34 * Then an error message string followed by a <newline>.
35
36 The contents of the error message strings shall be the same as those
37 returned by strerror() with argument errno.
38
39 The perror() function shall mark for update the last data modification
40 and last file status change timestamps of the file associated with the
41 standard error stream at some time between its successful completion
42 and exit(), abort(), or the completion of fflush() or fclose() on
43 stderr.
44
45 The perror() function shall not change the orientation of the standard
46 error stream.
47
48 On error, perror() shall set the error indicator for the stream to
49 which stderr points, and shall set errno to indicate the error.
50
51 Since no value is returned, an application wishing to check for error
52 situations should call clearerr(stderr) before calling perror(), then
53 if ferror(stderr) returns non-zero, the value of errno indicates which
54 error occurred.
55
57 The perror() function shall not return a value.
58
60 Refer to fputc().
61
62 The following sections are informative.
63
65 Printing an Error Message for a Function
66 The following example replaces bufptr with a buffer that is the neces‐
67 sary size. If an error occurs, the perror() function prints a message
68 and the program exits.
69
70 #include <stdio.h>
71 #include <stdlib.h>
72 ...
73 char *bufptr;
74 size_t szbuf;
75 ...
76 if ((bufptr = malloc(szbuf)) == NULL) {
77 perror("malloc"); exit(2);
78 }
79 ...
80
82 Application writers may prefer to use alternative interfaces instead of
83 perror(), such as strerror_r() in combination with fprintf().
84
86 None.
87
89 None.
90
92 fprintf(), fputc(), psiginfo(), strerror()
93
94 The Base Definitions volume of POSIX.1‐2008, <stdio.h>
95
97 Portions of this text are reprinted and reproduced in electronic form
98 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
99 -- Portable Operating System Interface (POSIX), The Open Group Base
100 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
101 cal and Electronics Engineers, Inc and The Open Group. (This is
102 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
103 event of any discrepancy between this version and the original IEEE and
104 The Open Group Standard, the original IEEE and The Open Group Standard
105 is the referee document. The original Standard can be obtained online
106 at http://www.unix.org/online.html .
107
108 Any typographical or formatting errors that appear in this page are
109 most likely to have been introduced during the conversion of the source
110 files to man page format. To report such errors, see https://www.ker‐
111 nel.org/doc/man-pages/reporting_bugs.html .
112
113
114
115IEEE/The Open Group 2013 PERROR(3P)