cancelling fdopen(3)

simon at its63b.UUCP simon at its63b.UUCP
Thu Dec 11 02:38:36 AEST 1986


In article <88 at dcl-csvax.comp.lancs.ac.uk> stephen at comp.lancs.ac.uk (Stephen J. Muir) writes:
>I need to open a file, then allocate a FILE * structure to it:
>
>FILE *f_fd = fdopen (fd, "w");
>
>Now, what is the best way to release the FILE * structure to the free pool
>without closing the file attached to the original "fd"?
>

Well, the easiest way would be to put
	FILE *f_fd = fdopen (dup(fd), "w");
and then you can release the FILE * structure with fclose(f_fd),
which will close only the dup of fd, not fd itself.

--
Simon Brown
Department of Computer Science, University of Edinburgh, Scotland.
...!{ihnp4,seismo,decvax}!mcvax!ukc!cstvax(!its63b)!simon

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Life's a load of tripe - that's my gripe". [Anon.]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the Comp.unix.wizards mailing list