Change defines for stdin, stdout and stderr

Thomas Pfaff tpfaff@gmx.net
Tue Jun 17 06:57:00 GMT 2003


Hello all,

a few weeks ago i created a patch for cygwin to enable thread safe 
errnos by defining __DYNAMIC_REENT__. While this went smoothly (define 
__DYNAMIC_REENT__ and create __getreent) and is now included in cygwin i 
  discovered that stdin, stdout and stderr are defined directly with _REENT.

#define	stdin	(_REENT->_stdin)
#define	stdout	(_REENT->_stdout)
#define	stderr	(_REENT->_stderr)

This is a bit ugly because it requires that every app and lib must be 
recompiled for the _REENT change.

To avoid this in the future i would suggest to change the defines for 
stdin, stdout and stderr similar to errno.

#define stdin (*__stdin())
extern  __FILE **__stdin _PARAMS ((void));

and implement as

__FILE **
__stdin ()
{
   return &_REENT->_stdin;
}

Same for stdout and err. This would allow to define and undefine 
__DYNAMIC_REENT__ without recompiling user code.
I think that this is cleaner.

Comments are welcome.

TIA,
Thomas



More information about the Newlib mailing list