The <errno.h> header file contains declarations for defined error conditions. Many C functions set errno to specific values, depending on the type of error. These values are also defined in the <errno.h> header file. The implementation of errno contains a function call.
The following errno macros indicate an OS/400 system exception:
For a list of errno macro values, see ILE C/C++ Run-Time Library Functions.
Your program should always initialize errno to 0 (zero) before calling a function because errno is not reset by any library functions. Check for the value of errno immediately after calling the function that you want to check. You should also initialize errno to zero after an error has occurred.
Your program can use the strerror() and perror() functions to print the value of errno. The strerror() function returns a pointer to an error message string that is associated with errno. The perror() function prints a message to stderr. The perror() and strerror() functions should be used immediately after a function is called because subsequent calls might alter the errno value.
The following figure shows how to check the errno value for the fopen() function.
Figure 161. ILE C Source to Check the errno Value for fopen()
|
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.