Class Reference errno.h

Error codes for C++ macros. More...

Member

int get_errno()
void set_errno(int e)
int EDOM
int ERANGE
int EILSEQ
int EINVAL
int ENOENT
int ENOMEM
int EACCES
int EEXIST
int EIO
int EBUSY
int EAGAIN
int EPIPE

Detailed Description

Error codes for C++ macros. Load with #include <errno.h> or #include <cerrno> (same plugin). Available from LayoutEditor 20260918.

On every C library, errno is a macro, not a variable you can assign. In a LayoutEditor macro you therefore cannot write errno = 0. Use the two functions below.

Many C functions store a small integer when they fail (file not found, invalid argument, …). That integer is the “errno value”. The named constants (ENOENT, EDOM, …) are those numbers so you can compare without memorizing codes.

Example

#include <errno.h>

int main(){
    set_errno(0);
    if (get_errno() != 0) return 1;
    set_errno(EDOM);
    cout("EDOM = ", EDOM, "  current = ", get_errno(), "\n");
    set_errno(0);
}

The named constants (ENOENT, EDOM, …) are int values. Exact numbers can differ between operating systems; always compare by name, not by a hardcoded number. POSIX names exist only if the host C library defines them.

Member Function Documentation


int errno.h::get_errno()

Reads the current error code stored by the C library.

Parameters: none.

Returns: int — 0 means “no error” (if you cleared it). Any other value is a code; compare it to the constants below.


void errno.h::set_errno(int e)

Writes the error code. Call set_errno(0) before a sequence of calls if you want to know whether this call failed.

Parameters:

  • e (int) — new code. Use 0 to clear, or a constant such as EDOM.

Returns: nothing.


int errno.h::EDOM

Mathematics: argument outside the domain (for example square root of a negative number in some libraries).


int errno.h::ERANGE

Result too large or too small to be represented (overflow / underflow).


int errno.h::EILSEQ

Illegal byte sequence (invalid encoding).


int errno.h::EINVAL

Invalid argument passed to a function.


int errno.h::ENOENT

No such file or directory.


int errno.h::ENOMEM

Not enough memory.


int errno.h::EACCES

Permission denied.


int errno.h::EEXIST

File already exists (for example creating a file that is already there).


int errno.h::EIO

Input/output error.


int errno.h::EBUSY

Resource busy (already in use).


int errno.h::EAGAIN

Resource temporarily unavailable; try again later.


int errno.h::EPIPE

Broken pipe (writing to a closed pipe).

GNU-only extra names are not added by this plugin.

Python: import errno. This include is for C++ macros only.