Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ strerror(S) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

clearerr(S)

ferror(S)

perror(S)


 strerror(S)                    6 January 1993                    strerror(S)


 Name

    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), ferror(S), perror(S)

 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 exe-
    cuted.  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



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026