This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: oldhand cygwinner needed: RE: __errno_location() like functionality in Cygwin


"Robinow, David" <drobinow@dayton.adroit.com> wrote:

> > As I already mentioned, that approach works fine in Linux. As 
> > far as I know,
> > similar mechanisms are provided by FreeBSD (__error()), 
> > Solaris (___errno()),
> > UnixWare (__thr_errno()).
> > 
> > Is it true that Cygwin has no analogous functionality?
>  I have not actually used threads under Cygwin so I may
> be completely wrong here, but here's what I think.
> 
> /usr/include/sys/errno.h defines errno as a macro  (int * __errno)
>  __errno is provided by the operating system.  You do not have
> to create this yourself.

__errno is provided not by the OS, but by the Cygwin1.dll - Cygwin's
libc run-time. As far as I know from the sources, Cygwin doesn't allocate
new errno instance for each new created thread. It uses _impure_ptr defined
as _REENT everywhere in the code.

>   You do not want to define errno yourself.
> Delete any declarations of errno in your program.
> You can use errno in your program and it will be thread safe.
>   It just works.

I'm afraid it doesn't.

>  Somebody please tell me if I'm wrong.

Okay, seems it's time to discuss what should be done to achieve
needed functionality. I propose introduce new Cygwin function
set_errno_location_handler((int* (*__errno_location)(void)))
which will set Cygwin internal __errno() pointer to the new one.

Something like this:

static int *CYGWIN__errno(void)
{
  return &_REENT->_errno;
}

int* (*__errno)(void) = CYGWIN__errno;

void set_errno_location_handler(int* (*new__errno)(void))
{
    __errno = new__errno;
}

Any comments?
--
Dmitry.



--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]