|
NAMEperror , strerror ,
strerror_l , strerror_r ,
sys_errlist , sys_nerr —
system error messages
LIBRARYStandard C Library (libc, -lc)SYNOPSIS#include <stdio.h>
void
extern const char * const sys_errlist[];
char *
char *
int
DESCRIPTIONThestrerror (), strerror_l (),
strerror_r (), and perror ()
functions look up the error message string corresponding to an error number.
The The The The If the error number is not recognized, these functions return an
error message string containing “ If insufficient storage is provided in
strerrbuf (as specified in
buflen) to contain the error string,
The message strings can be accessed directly using the external
array sys_errlist. The external value
sys_nerr contains a count of the messages in
sys_errlist. The use of these variables is deprecated;
EXAMPLESThe following example shows how to useperror () to
report an error.
#include <fcntl.h> #include <stdio.h> #include <stdlib.h> int main(void) { int fd; if ((fd = open("/nonexistent", O_RDONLY)) == -1) { perror("open()"); exit(1); } printf("File descriptor: %d\n", fd); return (0); } When executed, the program will print an error message along the
lines of ‘ SEE ALSOintro(2), err(3), psignal(3)STANDARDSTheperror () and strerror ()
functions conform to ISO/IEC 9899:1999
(“ISO C99”). The
strerror_r () function conforms to
IEEE Std 1003.1-2001 (“POSIX.1”). The
strerror_l () function conforms to
IEEE Std 1003.1-2008 (“POSIX.1”).
HISTORYThestrerror () and perror ()
functions first appeared in 4.4BSD. The
strerror_r () function was implemented in
FreeBSD 4.4 by Wes Peters
<wes@FreeBSD.org>. The
strerror_l () function was added in
FreeBSD 13.0.
BUGSThestrerror () function returns its result in a static
buffer which will be overwritten by subsequent calls.
Programs that use the deprecated sys_errlist variable often fail to compile because they declare it inconsistently. Size of the sys_errlist object might increase during FreeBSD lifetime, breaking some ABI stability guarantees.
Visit the GSP FreeBSD Man Page Interface. |