Redirection of stderr
David Zink
zink at panix.uucp
Fri Mar 29 16:00:51 AEST 1991
In article <3181 at inews.intel.com>, bhoughto at pima.intel.com,
(Blair P. Houghton) sez:
( About using memcpy to duplicate FILEs )
>You're lucky, and probably don't close either of them, which
>closes both of them, regardless of whether a FILE object holds
>the state, because the kernel is now free to unlink the file.
(Given NFS, the kernal is _always_ free to unlink the file.)
>
> --Blair
I thought more fun was to close one and then open another file . . . .
if ((fp = fopen("logfile", "a+")) != (FILE *)0)
{
setbuf(fp, (char *)0);
memcpy((char *)stderr, (char *)fp, sizeof(*fp));
fclose(fp);
}
if ((fp = fopen("database", "r+")) == (FILE *)0)
{
perror("database");/* May even succeed if it writes to fd 2 directly */
exit(1);/*NOTREACHED*/
}
fprintf(stderr, "Beginning operations\n");
. . .
Looks good to me!
David
/*{fflush(a);close(fileno(a));fileno(a)=dup(fileno(b));} Works some places.*/
. . . if you must . . .
More information about the Comp.unix.internals
mailing list