[ECOS] Change output stream for printf

Nick Garnett nickg@ecoscentric.com
Mon Nov 15 18:33:00 GMT 2004


Andrew Lunn <andrew@lunn.ch> writes:

> On Mon, Nov 15, 2004 at 11:32:07AM -0500, Nicolas Brouard wrote:
> > Hi,
> > I would like to change the output stream for printf.
> 
> Do you realy mean stream here? If so, than its reasonably easy.  Edit
> packages/language/c/libc/stdio/current/src/common/stdout.cxx
> 
> any replace the libc stream with your stream. 
> 
> If you don't mean stream here, then it is much more difficult.
> 
> > For now, my printf
> > function puts characters over serial channel (with tty-mode serial device
> > driver on hardware serial device driver).
> > I would like printf puts characters over a socket for example.
> > How can I change the behaviour of printf?
> > I know that I can use diag_init_putc() to do that for diag_printf, but for
> > printf?
> 
> A quick hack would be to write your own vsnprintf() which called
> diag_vsprintf() to do all the work and then write the resulting string
> over your socket.

Another approach would be to use fileno(stdout) to get the file
descriptor underneath stdout (it should be 1). close() it and then
dup2() the socket into that descriptor. This is how it is done in *NIX
and it should work in eCos. You may need to do a bit of business to
flush any data still in the stream buffers.

-- 
Nick Garnett                    eCos Kernel Architect
http://www.ecoscentric.com/     The eCos and RedBoot experts


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss



More information about the Ecos-discuss mailing list