Chinaunix首页 | 论坛 | 博客
  • 博客访问: 263594
  • 博文数量: 52
  • 博客积分: 1379
  • 博客等级: 大尉
  • 技术积分: 525
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-18 17:34
文章分类

全部博文(52)

文章存档

2011年(48)

2010年(4)

分类: LINUX

2011-03-13 10:41:13

$ 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;

阅读(2153) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~