On Thu, Apr 04, 2002 at 06:47:13PM +0300, Nadav Har'El wrote:
> On Thu, Apr 04, 2002, mulix wrote about "Re: c question":
> > On Thu, Apr 04, 2002 at 06:17:16PM +0300, Nadav Har'El wrote:
> >     stdout = fopen("/my/logging/file"); 
> >     stderr = fopen("/my/other/logging/file");
> 
> Ok, I get your point. I don't remember seeing any program doing something
> like that, but I guess it's conceivable, and that using fileno() might be a
> wise idea.

i'm pretty sure i've picked it up somewhere, perhaphs at steven's
APUE. wherever it was, it's a good practice, and you get the added
benefit of readability of the code. 

> One last point though: it is not portable to assign to stdout, etc. like
> you showed above. In Linux you can do this, because stdout is defined as
> 
>       extern FILE *stdout;            /* Standard output stream.  */
> 
> but in other UNIX systems you can't. For example, in Solaris (8, at least),
> and in all AT&T-based systems I knew, stdout is defined as
>       #define stdout  (&__iob[1])
> 
> And you obviously cannot assign to this. You may, perhaps, do
>       *stdout=*fopen(...);
> but that is really funky and again non-portable; Instead, the portably ANSI-
> C solution is to use the freopen() function.

true. my example was scratch code - please treat it as such. 
-- 
The ill-formed Orange
Fails to satisfy the eye:       http://vipe.technion.ac.il/~mulix/
Segmentation fault.             http://syscalltrack.sf.net/

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to