← GCC/C Index

❌ <errno.h> — Error Number Definitions

Defines the global variable errno and symbolic error constants. Set by system calls and library functions on error. Use with perror() or strerror().

Include: #include <errno.h> | Compile: gcc -Wall -o prog prog.c

📋 Functions & Macros

NamePrototype / ValueDescription
errnoextern int errnoGlobal error number — set by failing system calls
EPERM1Operation not permitted
ENOENT2No such file or directory
EINTR4Interrupted system call
EIO5I/O error
EBADF9Bad file descriptor
ENOMEM12Out of memory
EACCES13Permission denied
EEXIST17File exists
EINVAL22Invalid argument
ERANGE34Result too large

💡 Example Program

Copy, save as demo.c, and compile with the command shown at the bottom.

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

int main(void) {
    FILE *fp = fopen("/no/such/file.txt", "r");
    if (fp == NULL) {
        perror("fopen");
        printf("errno=%d : %s\n", errno, strerror(errno));
    }

    errno = 0;
    long val = strtol("99999999999999999", NULL, 10);
    if (errno == ERANGE)
        printf("Overflow! val=%ld errno=%d (%s)\n",
               val, errno, strerror(errno));
    return 0;
}
/* Compile: gcc -Wall -o errno_demo errno_demo.c */

← <time.h>  |  🏠 Index  |  <stdint.h> →