>Sometimes library functions as well as system calls need to set errno.
Right.
>Depending on whether something is linked with _REENTRANT or not, errno
>may be per-thread, or global.
It's always per-thread. (Well, to a point. The main thread's errno
is the global variable so thread-safe code and unsafe code will use the
same errno if there's but one thread.
>libc has internal magic to do the right thing regardless of whether or not
>what it is
>dynamically linked to was compiled with _REENTRANT.
>
>But it does not appear to make that magic publically available.
Sure it is; just compile with -D_REENTRANT and you're all set.
The magic errno is:
(*(___errno()))
___errno is a function returning a pointer to the per-thread errno variable.
(*(___errno()) then is both an integer and an lvalue.
The magic with the main thread and the global errno variable happens
here:
usr/src/lib/libc/port/threads/thr.c:1429
self->ul_errnop = &errno;
line 2823 sets this for other threads:
ulwp->ul_errnop = &ulwp->ul_errno;
Casper
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code