errno

suggest change

<errno.h> defines errno, a modifiable thread-local-style facility used by some library functions to report additional error information. A function's documentation determines whether it uses errno; a nonzero value alone does not prove that the most recent call failed.

The standard defines at least these error macros:

Macro Meaning
EDOM Domain error
ERANGE Range error
EILSEQ Illegal multibyte character sequence

An implementation may define additional values.

Only inspect errno after a function indicates failure in a way documented for that function. If the function can return its failure value on success, set errno to zero before the call and inspect it afterward:

#include <errno.h>
#include <stdlib.h>

errno = 0;
char *end;
long value = strtol(text, &end, 10);

if (errno == ERANGE) {
    /* The mathematical result was outside long's range. */
}

A successful library call may leave errno unchanged, and another library call may overwrite it. Save the value promptly if it will be needed later.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents