This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Confused about fflush(NULL)
- From: Tim Cussins <timcussins at eml dot cc>
- To: newlib at sources dot redhat dot com
- Date: Thu, 29 Sep 2011 14:36:34 +0100
- Subject: Confused about fflush(NULL)
Hi all,
I'm a bit confused about what's supposed to happen when I call fflush(NULL).
I should be using fflush(stdout) and this works fine. But I felt that
fflush(NULL) should work too and it doesn't.
Here's why (from newlib/stdio/fflush.c):
int
_DEFUN(fflush, (fp),
register FILE * fp)
{
if (fp == NULL)
return _fwalk_reent (_GLOBAL_REENT, _fflush_r);
return _fflush_r (_REENT, fp);
}
Which agrees with:
http://sourceware.org/newlib/libc.html#fflush
I presume that, in my setup, _GLOBAL_REENT has no knowledge of the
FILE*s in _REENT, as far as I can tell. Can someone please clarify the
contract between _REENT and _GLOBAL_REENT?
In particular, should I be expecting fflush(NULL) to flush my thread's
stdout? If so, what do I need to wire up?
I'm working with FreeRTOS and the latest RTEMS toolchain (4.11) for ppc405.
When I create a thread:
{
reent = malloc(struct _reent));
if ( reent == NULL )
return -1;
_REENT_INIT_PTR(((struct _reent* )reent));
}
and on thread switch:
{
_impure_ptr = reent;
}
Any advice, tips and abuse would be warmly, warmly and grudgingly
welcomed, respectively.
Thanks in advance :)
Tim