6.4 <errno.h> Errors

The header file errno.h consists of macros that provide error codes that are reported by certain library functions. The variable errno might be assigned any value greater than zero by these library functions. Preprocessor macros are defined to represent these values. Library functions will never set errno to zero. At program start-up, errno is zero.

To test if a library function encounters an error, the program should store the zero value in errno immediately before calling the library function. The value should be checked after the call, before subsequent code can change the value.

errno Macro/Variable

Contains the value of an error when an error occurs in several library functions.

Include

<errno.h>

Remarks

This is implemented as a macro that aliases the int object __errno_val with all MPLAB XC implementations except for XC8 PIC, where it is defined as an int object in its own right.

The value of errno will be zero at program startup. It is set to a non-zero integer value by certain library functions when an error occurs. The errno object should be reset to zero prior to calling a function that may set it.

EDOM Macro

Represents a domain error.

Include

<errno.h>

Remarks

EDOM represents a domain error, which occurs when an input argument is outside the domain in which the function is defined.

EILSEQ Macro

Represents a wide character encoding error.

Include

<errno.h>

Remarks

EILSEQ represents a wide character encoding error, when the character sequence presented to the underlying mbrtowc function does not form a valid (generalized) multibyte character, or if the code value passed to the underlying wcrtomb does not correspond to a valid (generalized) overflow or underflow error, which occurs when a result is too large or too small to be stored.

ERANGE Macro

Represents an overflow or underflow error.

Include

<errno.h>

Remarks

ERANGE represents an overflow or underflow error, which occurs when a result is too large or too small to be stored.