Global macros that hold error codes that are set during program execution, and string equivalents of the error codes for display.
#define errno (*_errno()) #define _doserrno (*__doserrno()) #define _sys_errlist (__sys_errlist()) #define _sys_nerr (*__sys_nerr())
_doserrno are set to 0 by the runtime during program startup.
errno is set on an error in a system-level call. Because
errno holds the value for the last call that set it, this value may be changed by succeeding calls. Run-time library calls that set
errno on an error do not clear
errno on success. Always clear
errno by calling
_set_errno(0) immediately before a call that may set it, and check it immediately after the call.
On an error,
errno is not necessarily set to the same value as the error code returned by a system call. For I/O operations,
_doserrno stores the operating-system error-code equivalents of
errno codes. For most non-I/O operations, the value of
_doserrno is not set.
errno value is associated with an error message in
_sys_errlist that can be printed by using one of the
perror functions, or stored in a string by using one of the
strerror_s functions. The
strerror functions use the
_sys_errlist array and
_sys_nerr—the number of elements in
_sys_errlist—to process error information. Direct access to
_sys_nerr is deprecated for code-security reasons. We recommend that you use the more secure, functional versions instead of the global macros, as shown here:
|Global Macro||Functional Equivalents|
Library math routines set
errno by calling
_matherr. To handle math errors differently, write your own routine according to the
_matherr reference description and name it
errno values are predefined constants in
<errno.h>, and are UNIX-compatible. Only
EDOM are specified in the ISO C99 standard. For a complete list, see errno Constants.
|Global macro||Required header||Optional header|
_sys_nerr macros are Microsoft extensions. For more compatibility information, see Compatibility.
Submit and view feedback for