1

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?

Some Name
  • 8,555
  • 5
  • 27
  • 77
  • That doesn't look like the [thread safe definition](https://stackoverflow.com/questions/1694164/is-errno-thread-safe). – tadman Jul 04 '18 at 17:50
  • 1
    @tadman Ah, I did not notice `define errno (*__errno_location ())` which may be a thread safe. – Some Name Jul 04 '18 at 17:51

0 Answers0