Steve Graegert wrote:

> > > Is it a bad pratice? Is there a 'limit' for 'errno' usage?
> > 
> > No; there's no reason you can't use errno for your own purposes.
> 
> This is acceptable for most cases but is not recommended for
> multithreaded applications since two or more threads may set the
> globally defined errno variable to report errors, but its use may
> result it nondeterministic behavior.

In GNU libc 2.x, errno is a macro which refers to a thread-specific
location.

> When using errno in a multithreaded environment (which is not
> explicitly recommended by POSIX but acceptable to retain
> compatibility) ISO/IEC 9945:1-1996 defines that errno.h should be
> included in every source file to make sure that every thread accesses
> its own errno variable to check for errors.  This is crucial to create
> libraries that conform to POSIX and are reentrant.

Just to clarify: if you read or set errno, you have to include
<errno.h>; don't use "extern int errno" (which will work on some
systems, but not with glibc).

-- 
Glynn Clements <[EMAIL PROTECTED]>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" 
in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to