DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

strerror(S-osr5)


strerror -- gets error message pointer from last routine call error

Syntax

cc . . . -lc

#include  <string.h>

char *strerror(errnum) int errnum;

Description

The strerror routine maps errnum to an error-message string, returning a pointer to the string. The function itself does not actually print the message; for that, you need to call an output function such as printf.

Return value

The strerror function returns a pointer to the error-message string. The string can be overwritten by subsequent calls to strerror.

See also

clearerr(S-osr5), ferror(S-osr5), perror(S-osr5)

Standards conformance

strerror is conformant with: ANSI X3.159-1989 Programming Language -- C .

Example

   #include <string.h>
   #include <errno.h>
   #include <fcntl.h>
   #include <sys/types.h>
   #include <sys/stat.h>
   

extern int errno; int errnum; int fh1, fh2;

main() { errnum=0; if ((fh1=open("xxxx",O_RDONLY)) == -1) errnum=errno; fh2=open("yyyy",O_RDONLY);

/* Other code that may set the errno value.*/ if (errnum != 0) printf(strerror(errnum)); }

The program shown above tries to open files xxxx and yyyy. If an error occurs opening xxxx, the variable errnum is set to the errno value returned by open. Other code that may alter the errno value is then executed. Later, the saved errno value in errnum is checked and, if nonzero, an error message assigned to it by strerror is printed. If file xxxx does not exist, the example prints the following message:
   No such file or directory

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005