Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
STRERROR(3)		 BSD Library Functions Manual		   STRERROR(3)

     perror, strerror, strerror_r, sys_errlist,	sys_nerr -- system error mes-

     Standard C	Library	(libc, -lc)

     #include <stdio.h>

     perror(const char *string);

     extern const char * const sys_errlist[];
     extern const int sys_nerr;

     #include <string.h>

     char *
     strerror(int errnum);

     strerror_r(int errnum, char * strerrbuf, size_t buflen);

     The strerror(), strerror_r() and perror() functions look up the error
     message string corresponding to an	error number.

     The strerror() function accepts an	error number argument errnum and re-
     turns a pointer to	the corresponding message string.

     The strerror_r() function renders the same	result into strerrbuf for a
     maximum of	buflen characters and returns 0	upon success.

     The perror() function finds the error message corresponding to the	cur-
     rent value	of the global variable errno (intro(2))	and writes it, fol-
     lowed by a	newline, to the	standard error file descriptor.	 If the	argu-
     ment string is non-NULL and does not point	to the null character, this
     string is prepended to the	message	string and separated from it by	a
     colon and space (`: '); otherwise,	only the error message string is

     If	errnum is not a	recognized error number, strerror() returns an error
     message string containing "Unknown	error: " followed by the error number
     in	decimal	and sets errno to EINVAL.  strerror_r()	leaves strerrbuf un-
     changed and returns EINVAL.  Error	numbers	recognized by this implementa-
     tion fall in the range 0 <= errnum	< sys_nerr.

     If	insufficient storage is	provided in strerrbuf (as specified in buflen)
     to	contain	the error string, strerror_r() returns ERANGE and strerrbuf
     will contain an error message that	has been truncated and nul terminated
     to	fit the	length specified by buflen.

     The message strings can be	accessed directly using	the external array
     sys_errlist.  The external	value sys_nerr contains	a count	of the mes-
     sages in sys_errlist.  The	use of these variables is deprecated;
     strerror()	or strerror_r()	should be used instead.

     intro(2), psignal(3)

     The strerror() and	perror() functions first appeared in 4.4BSD.  The
     strerror_r() function was implemented in FreeBSD 4.4 by Wes Peters

     For unknown error numbers,	the strerror() function	will return its	result
     in	a static buffer	which may be overwritten by subsequent calls.

     Programs that use the deprecated sys_errlist variable often fail to com-
     pile because they declare it inconsistently.

BSD				 Nov 26, 2001				   BSD


Want to link to this manual page? Use this URL:

home | help