Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

<errno.h> — error codes

The <errno.h> header provides errno and error-code macros. Interpret them according to the called function's contract.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <errno.h>

<errno.h> defines the errno macro: a modifiable lvalue of type int with thread storage duration, not an ordinary global variable. Do not suppress this macro or declare your own identifier named errno.

EDOM, EILSEQ, and ERANGE represent domain, encoding, and range errors respectively. They are distinct positive constants of type int; compare names, not numbers.

Check errno only according to the function's contract: a nonzero value alone does not prove failure. When clearing is required, set errno = 0 before the call; read or save the result before another library call. Library functions do not automatically clear errno.

Examples

#include <errno.h>
#include <stdio.h>

int main(void)
{
    errno = ERANGE;
    int saved_error = errno;
    errno = 0;
    int cleared = errno == 0;

    printf("saved ERANGE: %d\n", saved_error == ERANGE);
    printf("cleared: %d\n", cleared);
    return 0;
}

Result

saved ERANGE: 1
cleared: 1

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources