HOME

TheInfoList



OR:

errno.h is a
header file Many programming languages and other computer files have a directive, often called include (sometimes copy or import), that causes the contents of the specified file to be inserted into the original file. These included files are called copybooks ...
in the standard library of the
C programming language ''The C Programming Language'' (sometimes termed ''K&R'', after its authors' initials) is a computer programming book written by Brian Kernighan and Dennis Ritchie, the latter of whom originally designed and implemented the language, as well as ...
. It defines macros for reporting and retrieving error conditions using the symbol errno (short for "error number").International Standard for Programming Language C (C11), ISO/IEC 9899:2011, p. 205 errno acts like an integer variable. A value (the error number) is stored in errno by certain
library function In computer science, a library is a collection of non-volatile resources used by computer programs, often for software development. These may include configuration data, documentation, help data, message templates, pre-written code and su ...
s 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.International Standard for Programming Language C (C99), ISO/IEC 9899:1999, p. 186 Most functions indicate that they detected an error by returning a special value, typically
NULL Null may refer to: Science, technology, and mathematics Computing * Null (SQL) (or NULL), a special marker and keyword in SQL indicating that something has no value * Null character, the zero-valued ASCII character, also designated by , often use ...
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. Originally this was a static memory location, but macros are almost always used today to allow for multi-threading, so that each thread will see its own thread-local 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. ERANGE :Results from a result outside a function's range, e.g. on systems with a 32-bit wide long EILSEQ (Required since 1994 Amendment 1 to C89 standard) :Results from an illegal byte sequence, e.g. on systems that use
UTF-8 UTF-8 is a variable-width encoding, variable-length character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode'' (or ''Universal Coded Character Set'') ''Transformation Format 8-bit'' ...
.
POSIX The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application programming interf ...
compliant
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
s like
AIX Aix or AIX may refer to: Computing * AIX, a line of IBM computer operating systems *An Alternate Index, for a Virtual Storage Access Method Key Sequenced Data Set * Athens Internet Exchange, a European Internet exchange point Places Belgi ...
,
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
or
Solaris Solaris may refer to: Arts and entertainment Literature, television and film * ''Solaris'' (novel), a 1961 science fiction novel by Stanisław Lem ** ''Solaris'' (1968 film), directed by Boris Nirenburg ** ''Solaris'' (1972 film), directed by ...
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.
C++11 C++11 is a version of the ISO/ IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versions b ...
additionally defines many of the same values found within the POSIX specification. Traditionally, the first page of Unix system manuals, named intro(2), lists all errno.h macros, but this is not the case with
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
, where these macros are instead listed in the errno(3). An can be translated to a descriptive string using strerror (defined in string.h) or a BSD extension called . The translation can be printed directly to the standard error stream using
perror The C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header . The functionality descends from a "portable I/O package" written by Mike Lesk ...
(defined in stdio.h). As in many Unix-like systems is not thread-safe, a thread-safe version is used, but conflicting definitions from POSIX and GNU makes it even less portable than the table.


See also

*
perror The C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header . The functionality descends from a "portable I/O package" written by Mike Lesk ...
* strerror


References


Bibliography

*


External links

* *{{man, 3, errno, Linux
GNU C library manual: Error codes
C standard library headers