Stream redirection in Linus GCC
Hi.
I work in Debian Linux GCC. I have a function, which opens a socket and
binds 'mystream' stream with this socket (by fdopen command). Then, while
being inside this function I want stdout be redirected to mystream. On
exiting the function I have to return stdout to ordinary stdout.
I did it like this:
Entering function
{
..
FILE* sos_stdout;
sos_stdout = stdout; //reserving stdout
stdout = mystream; //redirecting
...
doing something
...
stdout = sos_stdout; //returning stdout back
fclose(mystream); //closing my stream
....
Exiting..
}
It works, but I still have a feeling that I do it in a wrong way. Please,
advise if it is really so.
Regards, Alex.
|