$ man errno
DESCRIPTION
The 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 return value of the call indicated an error (i.e., -1 from most system calls; -1 or
NULL from most library functions); a function that succeeds is allowed to change errno.
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.
errno是个thread local变量(其实不一定是变量)
errno只有在函数返回错误的时候才有意义
在多线程环境下,它通常是个宏
#define errno (*__errno_location ())
__errno_location用于实现thread local errno, 不同的线程库可能实现不一样
最简单的就是直接返回内部errno
__thread int errno;
阅读(2158) | 评论(0) | 转发(0) |