C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
strerror, _strerror
 Summary Example                         Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
     The strerror function 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 fprintf):
 
         if ( ( _access( "datafile",2 ) ) == -1 )
             fprintf( stderror, strerror( NULL ) );
 
     If <string> is passed as NULL, _strerror returns a pointer to a
     string containing the system error message for the last library
     call that produced an error. The error-message string is
     terminated by the newline character (\n).
 
     If <string> is not equal to NULL, _strerror returns a pointer to a
     string containing, in order, your string message, a colon, a
     space, the system error message for the last library call
     producing an error, and a newline character. Your string message
     can be a maximum of 94 bytes long.
 
     Unlike perror, _strerror alone does not print any messages. To
     print the message returned by _strerror to stderr, your program
     needs an fprintf statement, as shown below:
 
          if( ( _access( "datafile", 2 ) ) == -1 )
               fprintf( _strerror( NULL ) );
 
     The actual error number for _strerror is stored in the errno
     variable, which is declared in STDLIB.H. The system error messages
     are accessed through the variable _sys_errlist, which is an array
     of messages ordered by error number. The _strerror function
     accesses the appropriate error message by using the errno value as
     an index to _sys_errlist. The value of the variable _sys_nerr is
     defined as the maximum number of elements in the _sys_errlist
     array.
 
     To produce accurate results, _strerror should be called
     immediately after a library routine returns an error. Otherwise,
     the errno value may be overwritten by subsequent calls.
 
     Note that the _strerror function under Microsoft C version 5.0 is
     identical to the version 4.0 strerror function. The name was
     altered to permit the inclusion in Microsoft C version 5.0 of the
     ANSI-conforming strerror function. The _strerror function is not
     part of the ANSI definition but is instead a Microsoft extension
     to it; it should not be used where portability is desired. For
     ANSI compatibility, use strerror instead.
 
     Return Value
 
     Both the strerror and _strerror functions return a pointer to the
     error-message string. The string can be overwritten by subsequent
     calls to strerror or _strerror.
                                    -♦-