why is _REENT_SMALL_CHECK_INIT called in _printf_r/printf functions?
Can Finner
can.finner@gmail.com
Tue Jun 19 14:08:00 GMT 2012
Hi,
When _REENT_SMALL is defined, functions like _printf_r/printf call
_REENT_SMALL_CHECK_INIT at first.
int
_DEFUN(_printf_r, (ptr, fmt),
struct _reent *ptr _AND
const char *fmt _DOTS)
{
int ret;
va_list ap;
_REENT_SMALL_CHECK_INIT (ptr);
va_start (ap, fmt);
ret = _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
va_end (ap);
return ret;
}
I don't understand this very well, since in _vfprintf_r, CHECK_INIT
will be called which calls __sinit too.
The only thing affected is the 2nd argument passed to _vfprintf_r,
which points to a real FILE struct allocated in __sinit if
_REENT_SMALL_CHECK_INIT is called, otherwise it points to
__sf_fake_stdxx. Does this matter? Since CHECK_INIT called in
_vfprintf_r will point fp away from fake_stdxx anyway.
#define CHECK_INIT(ptr, fp) \
do \
{ \
if ((ptr) && !(ptr)->__sdidinit) \
__sinit (ptr); \
if ((fp) == (FILE *)&__sf_fake_stdin) \
(fp) = _stdin_r(ptr); \
else if ((fp) == (FILE *)&__sf_fake_stdout) \
(fp) = _stdout_r(ptr); \
else if ((fp) == (FILE *)&__sf_fake_stderr) \
(fp) = _stderr_r(ptr); \
} \
while (0)
I am not sure if I described my question correctly, please give any
comment you want and I will update the message.
Thanks very much.
--
Regards.
More information about the Newlib
mailing list