errno.h

From Infogalactic: the planetary knowledge core
(Redirected from Errno)
Jump to: navigation, search

Lua error in package.lua at line 80: module 'strict' not found. errno.h is a header file in the standard library of the C programming language. It defines macros for reporting and retrieving error conditions through error codes stored in a static memory location called errno (short for "error number").[1]

A value (the error number) is stored in errno by certain library functions when they detect errors. At program startup, the value stored is zero. Library functions store only values greater than zero. Any library function can alter the value stored before return, whether or not they detect errors. Most functions indicate that they detected an error by returning a special value, typically NULL for functions that return pointers, and −1 for functions that return integers. A few functions require the caller to preset errno to zero and test it afterwards to see if an error was detected.

The errno macro expands to an lvalue with type int, sometimes with the extern and/or volatile type specifiers depending upon the platform,[2] containing the last error code generated in any function using the errno facility.[1] Originally this was a static memory location, but macros are almost always used today to allow for multi-threading, such that each thread will see its own error number.

The header file also defines macros that expand to integer constants that represent the error codes. The C standard library only requires three to be defined:

EDOM

Results from a parameter outside a function's domain, e.g. sqrt(-1)

ERANGE

Results from a result outside a function's range, e.g. strtol("0xfffffffff",NULL,0) on systems with a 32-bit wide long

EILSEQ (Required since 1994 Amendment 1 to C89 standard)[3]

Results from an illegal byte sequence, e.g. mbstowcs(buf,"\xff", 1) on systems that use UTF-8.

POSIX compliant operating systems like AIX, Linux or Solaris include many other error values, many of which are used much more often than the above ones, such as EACCES for when a file cannot be opened for reading.[4] C++11 additionally defines many of the same values found within the POSIX specification.[5]

Traditionally, the first page of Unix system manuals, named intro(2), lists all errno.h macros, but this is not the case with Linux, where these macros are instead listed in the errno(3).[6]

See also

References

  1. 1.0 1.1 International Standard for Programming Language C (C99), ISO/IEC 9899:1999, p. 186
  2. Lua error in package.lua at line 80: module 'strict' not found.
  3. Lua error in package.lua at line 80: module 'strict' not found.
  4. errno.h: system error numbers – Base Definitions Reference, The Single UNIX® Specification, Issue 7 from The Open Group
  5. Lua error in package.lua at line 80: module 'strict' not found.
  6. Stevens & Rago 2013, p. 14.

Bibliography

  • Lua error in package.lua at line 80: module 'strict' not found.

External links