请输入您要查询的百科知识:

 

词条 Errno.h
释义

  1. See also

  2. References

  3. Bibliography

  4. External links

{{C Standard Library}}{{lowercase|title=errno.h}}errno.h is a header file in the standard library of the C programming language. It defines macros for reporting and retrieving error conditions using the symbol errno (short for "error number").[1]

errno acts like an integer variable. 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[2]. 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.[3] 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:[2]

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)[4]

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.[5] C++11 additionally defines many of the same values found within the POSIX specification.[6]

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).{{sfn|Stevens|Rago|2013|p=14}}

See also

  • stdio.h (for perror)
  • string.h (for strerror)

References

1. ^International Standard for Programming Language C (C11), ISO/IEC 9899:2011, p. 205
2. ^International Standard for Programming Language C (C99), ISO/IEC 9899:1999, p. 186
3. ^{{cite web |url=https://www.gnu.org/software/libc/manual/html_node/Checking-for-Errors.html |title=Checking for Errors |date=2014-02-08 |website=The GNU C Library (glibc) |publisher=GNU Project |accessdate=2014-06-25}}
4. ^{{cite web|url=http://www.lysator.liu.se/c/na1.html|title=A brief description of Normative Addendum 1|accessdate=2013-09-12}}
5. ^{{man|bd|errno.h|SUS|system error numbers}}
6. ^{{cite web |url=http://en.cppreference.com/w/cpp/error/errno_macros |title=Error numbers - cppreference.com |accessdate=2015-05-08 }}

Bibliography

  • {{cite book|last1=W. Richard|first1=Stevens|last2=Stephen A.|first2=Rago|title=Advanced Programming in the UNIX Environment|date=May 24, 2013|publisher=Addison-Wesley Professional|isbn=978-0321637734|edition=Third|url=http://www.kohala.com/start/apue.html|accessdate=27 February 2015}}

External links

  • FreeBSD System: Error codes
  • [https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html#index-ENOBUFS-117 GNU C library manual: Error codes]
  • [https://nuetzlich.net/errno.html Lists of errno values on Linux, both numeric and symbolic]

2 : C standard library headers|POSIX error codes

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/20 12:29:46