I'm a beginner in C programming and came across errno
declaration. I read man page of POSIX errno
and it is required to be thread-local. Here is the quote from man page:
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.
Now taking a look at errno.h
I found this:
/* Declare the `errno' variable, unless it's defined as a macro by
bits/errno.h. This is the case in GNU, where it is a per-thread
variable. This redeclaration using the macro still works, but it
will be a function declaration without a prototype and may trigger
a -Wstrict-prototypes warning. */
#ifndef errno
extern int errno;
#endif
And to my knowledge it does not look like a thread local variable. What does make errno
being thread-local?