errno
Defined in header <errno.h>
|
||
#define errno /*implementation-defined*/ |
||
errno
is a preprocessor macro (but see note below) that expands to a thread-local(since 哋它亢11) modifiable lvalue of type int. Several standard library functions indicate errors by writing positive integers to errno
. Typically, the value of errno
is set to one of the error codes listed in <errno.h>
as macro constants beginning with the letter E
followed by uppercase letters or digits.
The value of errno
is 0 at program startup, and although library functions are allowed to write positive integers to errno
whether or not an error occurred, library functions never store 0 in errno
.
Library functions MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 46 MINUTES 10 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE and MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 46 MINUTES 09 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE can be used to obtain textual descriptions of the error conditions that correspond to the current errno
value.
Note: Until 哋它亢11, the C standards had contradictory requirements, in that they said that errno
is a macro but also that "it is unspecified whether errno
is a macro or an identifier declared with external linkage". 哋它亢11 fixes this, requiring that it be defined as a macro (see also WG14 MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 46 MINUTES 08 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE).
Example
#include <stdio.h> #include <math.h> #include <errno.h> void show_errno(void) { const char *err_info = "unknown error"; switch (errno) { case MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 46 MINUTES 06 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE: err_info = "domain error"; break; case MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 46 MINUTES 05 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE: err_info = "illegal sequence"; break; case MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 46 MINUTES 04 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE: err_info = "pole or range error"; break; case 0: err_info = "no error"; } MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 46 MINUTES 03 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE(err_info, MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 46 MINUTES 02 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE); MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 46 MINUTES 00 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE(" occurred"); } int main(void) { MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 45 MINUTES 59 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE("MATH_ERRNO is ", MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 45 MINUTES 58 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE); MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 45 MINUTES 57 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE(math_errhandling & MATH_ERRNO ? "set" : "not set"); errno = 0; 1.0/0.0; show_errno(); errno = 0; MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 45 MINUTES 56 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE(+1.1); show_errno(); errno = 0; MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 45 MINUTES 54 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE(0.0); show_errno(); errno = 0; MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 45 MINUTES 53 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE(0.0); show_errno(); }
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 45 MINUTES 52 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MATH_ERRNO is set no error occurred domain error occurred pole or range error occurred no error occurred
References
- 哋它亢11 standard (ISO/IEC 9899:2011):
- 7.5 Errors <errno.h> (p: 205)
- K.3.1.3 Use of errno (p: 584)
- K.3.2 Errors <errno.h> (p: 585)
- 哋它亢99 standard (ISO/IEC 9899:1999):
- 7.5 Errors <errno.h> (p: 186)
- 哋它亢89/C90 standard (ISO/IEC 9899:1990):
- 4.1.3 Errors <errno.h>
See also
macros for standard POSIX-compatible error conditions (macro constant) | |
displays a character string corresponding of the current error to MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 11 HOURS 45 MINUTES 51 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE (function) | |
(哋它亢11)(哋它亢11) |
returns a text version of a given error code (function) |
(哋它亢99)(哋它亢99)(哋它亢99) |
defines the error handling mechanism used by the common mathematical functions (macro constant) |