This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: The reentrancy structure?


J. Johnston wrote:
> 
> Alright, now that I know what you want to do, there are a couple of things you
> haven't thought of.
> 
> First of all, the library routines dealing with default std streams, use
> the _r macros - e.g. a getchar() call won't link in your code.
> 

I have noticed that -- I wanted to modify them.

> Secondly, you have to deal with the std stream initialization routines in
> libc/stdio/findfp.c.  These routines get triggered by the CHECK_INIT macro
> which looks at the __sdidinit flag in the reent struct.
> 
> What you could do is to create a sys directory for your platform and add
> a sys/stdio.h header file.  In it, create a reference to an external integer
> (e.g. extern int __io_initialized; ).
> 
> Add your own versions of the std stream macros that are identical to the ones
> in stdio.h, only they also set __io_initialized to a value.
> 
> #define stdin  (__io_initialized = 1, _REENT->_stdin)
> #define _stdin_r(x)     (__io_initialized = 1, (x)->_stdin)

Interesting idea.

> Now, the only thing you have to do is skip the current definitions in stdio.h.
> Just protect them with a #ifndef __STD_STREAMS_DEFINED__ which you set in
> your sys/stdio.h.
>
> The __io_initialized integer is defined in your special code.  You will also want 
> to catch a user who might access the std file descriptors
> directly (e.g. write (2, "hello world\n", 12); ).  If you can dup2() the
> file descriptors, then you are set.  Otherwise, you should use freopen() so that 
> the __sdidinit flag is set and then you will have to intercept any base OS calls 
> that use the std fds so that they translate to the fds opened at initialization.

I'm not concerned about Unix-style file descriptors 0, 1, 2... -- I'm
using a non-Unix scheme for allocating file descriptors.  Since this
platform won't have processes, Unix software won't be able to port anyway.

	-hpa



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