Errno.h
Encyclopedia
Errno.h is a header file
Header file
Some programming languages use header files. These files allow programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers...

 in the standard library
C standard library
The C Standard Library is the standard library for the programming language C, as specified in the ANSI C standard.. It was developed at the same time as the C POSIX library, which is basically a superset of it...

 of C programming language
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

. It defines macros to report error conditions through error code
Error code
In computer programming, error codes are enumerated messages that correspond to faults in a specific software application. They are typically used to identify faulty hardware, software, or incorrect user input in programming languages that lack exception handling, although they are sometimes also...

s stored in a static location called errno.

A value 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, containing the last error code generated in any function using the errno facility. Originally this was a static memory location, but macros are almost always used today to allow for multi-threading, 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
C standard library
The C Standard Library is the standard library for the programming language C, as specified in the ANSI C standard.. It was developed at the same time as the C POSIX library, which is basically a superset of it...

 only require three to be defined:

EDOM
Results from a parameter outside a function's domain, for example sqrt(-1)


ERANGE
Results from a result outside a function's range, for example strtol("0xfffffffff",NULL,0)


EILSEQ
Results from an illegal byte sequence, for example mbstowcs(buf,"\xff", 1) (if the multi-byte encoding is UTF-8
UTF-8
UTF-8 is a multibyte character encoding for Unicode. Like UTF-16 and UTF-32, UTF-8 can represent every character in the Unicode character set. Unlike them, it is backward-compatible with ASCII and avoids the complications of endianness and byte order marks...

).


POSIX
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...

 compliant operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

s like UNIX
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 or Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

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.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK