Of csh & filepointers & fopen calls ...

brett at wjvax.UUCP brett at wjvax.UUCP
Thu Feb 12 03:06:20 AEST 1987


In article <638 at rtech.UUCP> bobm at rtech.UUCP (Bob Mcqueer) writes:
>I ran across this while trying to figure out how to tell following an
>fopen() call that the reason it failed was due to too many open file
>pointers.
>WHAT is csh doing with those 4 extra file pointers it apparently has open?
>WHAT does csh set up differently which causes the errno 24 to be hanging
>around after the fopen call (I assume coming from the underlying open())?

I don't have source, but I will hazard a guess.  The stdio package allocates
a static list of NOFILE entries, where NOFILE is the number of file descriptors
which can be open; stdin, stdout, and stderr are set to be already open.
When you fopen(), the stdio package first must find an entry in this list; then
it must open() the underlying file.  Apparently, csh leaves some other
file descriptors open across the exec(), which the stdio package can't
know about.  Thus, the stdio package still has entries available when
it runs out of file descriptors.  However, if the shell only leaves
stdin, stdout, and stderr open, the stdio package runs out of FILE entries
and file descriptors at the same time.  However, it must check for a
FILE entry first; otherwise the open might fail and yet leave the underlying
file open. Thus, fopen() returns error because there are no FILE entries
left, and the stdio package is too stupid to simulate an EMFILE error in
that case.

-- 
-------------
Brett Galloway
{pesnta,twg,ios,qubix,turtlevax,tymix,vecpyr,certes,isi}!wjvax!brett



More information about the Comp.unix.wizards mailing list