gtpc2m71C/C++ Language Support User's Guide

strerror-Get Pointer to Run-Time Error Message

This function maps the error number in the errnum field to an error message string. The error number must be a valid errno value.

Format

#include <string.h>
char *strerror(int errnum);

errnum
A valid errno value.

Normal Return

This function returns a pointer to the string, which may be overwritten by a subsequent call to the strerror function. Do not let the program modify the contents of this string.

Error Return

Not applicable.

Programming Considerations

The strings that are returned by the strerror function are defined in segment CBSTER. User modifications to these strings will affect strerror output.

Examples

The following example calls the sqrt() function and prints an error message if an error occurs.

#include <math.h>
#include <string.h>
#include <errno.h>
 
void test(double d)
{
   double r = 0.0;
   errno = 0;
   r = sqrt(d);
   if (errno != 0)
      printf("Error in sqrt:  %s\n", strerror(errno));
}

Related Information

None.