Chinaunix

标题: 关于errno [打印本页]

作者: phoxia    时间: 2011-08-09 15:02
标题: 关于errno
DESCRIPTION
       The  <errno.h> header file defines the integer variable errno, which is set by system calls and some library functions in
       the event of an error to indicate what went wrong.  Its value is significant only when the call returned an  error  (usu鈥[m
       ally -1), and a function that does succeed is allowed to change errno.

       Sometimes,  when -1 is also a valid successful return value one has to zero errno before the call in order to detect pos鈥[m
       sible errors.

       errno is defined by the ISO C standard to be a modifiable lvalue of type int, and must not be explicitly declared;  errno
       may be a macro.  errno is thread-local; setting it in one thread does not affect its value in any other thread.       Valid  error numbers are all non-zero; errno is never set to zero by any library function.  All the error names specified
       by POSIX.1 must have distinct values, with the exception of EAGAIN and EWOULDBLOCK, which may be the same.

       Below is a list of the symbolic error names that are defined on Linux.  Some of these are marked POSIX.1, indicating that
       the name is defined by POSIX.1-2001, or C99, indicating that the name is defined by C99.


errno是线程本地存储的?
另外如果recv系统调用导致errno被设置为EINTER,其它的系统调用如果调用成功了,errno有时会被设置为0,有时还是旧值,怎么回事情啊?
作者: 瀚海书香    时间: 2011-08-09 16:11
回复 1# phoxia
errno是线程存储的。
errno不会被置成0。
作者: phoxia    时间: 2011-08-10 09:47
线程存储的话,那么如果开10个线程,每个线程的errno都可能不同么?
作者: 瀚海书香    时间: 2011-08-11 14:50
回复 3# phoxia
因为是线程存储的,所以不同的线程errno的值是有可能不相同的。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2