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
12 perror - write error messages to standard error
13
15 #include <stdio.h>
16
17 void perror(const char *s);
18
19
21 The perror() function shall map the error number accessed through the
22 symbol errno to a language-dependent error message, which shall be
23 written to the standard error stream as follows:
24
25 * First (if s is not a null pointer and the character pointed to by s
26 is not the null byte), the string pointed to by s followed by a
27 colon and a <space>.
28
29 * Then an error message string followed by a <newline>.
30
31 The contents of the error message strings shall be the same as those
32 returned by strerror() with argument errno.
33
34 The perror() function shall mark the file associated with the standard
35 error stream as having been written (st_ctime, st_mtime marked for
36 update) at some time between its successful completion and exit(),
37 abort(), or the completion of fflush() or fclose() on stderr.
38
39 The perror() function shall not change the orientation of the standard
40 error stream.
41
43 The perror() function shall not return a value.
44
46 No errors are defined.
47
48 The following sections are informative.
49
51 Printing an Error Message for a Function
52 The following example replaces bufptr with a buffer that is the necesā
53 sary size. If an error occurs, the perror() function prints a message
54 and the program exits.
55
56
57 #include <stdio.h>
58 #include <stdlib.h>
59 ...
60 char *bufptr;
61 size_t szbuf;
62 ...
63 if ((bufptr = malloc(szbuf)) == NULL) {
64 perror("malloc"); exit(2);
65 }
66 ...
67
69 None.
70
72 None.
73
75 None.
76
78 strerror(), the Base Definitions volume of IEEE Std 1003.1-2001,
79 <stdio.h>
80
82 Portions of this text are reprinted and reproduced in electronic form
83 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
84 -- Portable Operating System Interface (POSIX), The Open Group Base
85 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
86 Electrical and Electronics Engineers, Inc and The Open Group. In the
87 event of any discrepancy between this version and the original IEEE and
88 The Open Group Standard, the original IEEE and The Open Group Standard
89 is the referee document. The original Standard can be obtained online
90 at http://www.opengroup.org/unix/online.html .
91
92
93
94IEEE/The Open Group 2003 PERROR(3P)