fdopen() problem in stdio

phil.rice%rand-relay at sri-unix.UUCP phil.rice%rand-relay at sri-unix.UUCP
Mon Nov 7 07:11:03 AEST 1983


From:  William LeFebvre <phil.rice at rand-relay>

   "The problem is that after <N> calls to the routine, fdopen() returns NULL
    because it runs out of FILE pointers (there is a static array of them in
    stdio).  I don't want to use fclose(), that would close the file
    descriptor.
    
    Anyone know a way to release a FILE pointer without closing the file
    itself?  Poking into the structure is not a solution I would like to
    consider."

Rather than doing the fdopen on the original file descriptor (with
fdopen(fd, ...)), you could do a fdopen(dup(fd), ...).  Then you can
call fclose() and not worry about the original file descriptor getting
closed.  Offhand, I think that this is the only way, short of mucking
around in _iob[], that you can do what you want to do.  The major
drawback to this scheme, of course, is that you can run out of file
descriptors (instead of FILE *'s) if you do this alot.

                                William LeFebvre
                                ARPANet: phil.rice at Rand-Relay
                                CSNet:   phil at rice
                                USENet:  ...!lbl-csam!rice!phil



More information about the Comp.unix.wizards mailing list