Newsgroups: comp.unix.internals Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!cmcl2!panix!zink From: zink@panix.uucp (David Zink) Subject: Re: Redirection of stderr Sender: zink@panix.uucp (David Zink) Message-ID: <1991Mar29.060051.15597@panix.uucp> Date: Fri, 29 Mar 91 06:00:51 GMT Organization: PANIX - Public Access Unix Systems of NY In article <3181@inews.intel.com>, bhoughto@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 . . .