ultrix 2.0 _iob storage

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Oct 28 07:44:03 AEST 1988


In article <575 at jim.odr.oz> jon at jim.odr.oz (Jon Wells) writes:
>#ifdef BSD
>nfiles = getdtablesize();
>#else
>nfiles = NFILES;
>#endif
>for ( p = &_iob[3]; p < _iob[nfiles]; p++ )
>	fclose(p);
>Is the above code deemed to be a reasonable way of doing this?

No, of course not.  One wonders what the code REALLY needed to do,
since this attempted drastic action would seldom be called for.

>Is _fwalk() standard on other genders of unix???

No _-prefixed identifier other than _exit is standard.

>Does everyone else store all the _iobuf's in _iob as one array?

No.  Many recent implementations dynamically allocate all but the
first three FILE structures.

>Or is there a much better way of closing everything but stdin etc.????

If an implementation conforms to the (proposed) ANSI C standard,
which most won't do for some time to come, then you can use
fflush((FILE*)NULL) to force buffered output to be sent to the
system.  Normally you only worry about this right before a fork,
and since most forks do no stdio before performing an exec, all
they need to do in this regard after the fork is to close the
extra file descriptors (not even trying to worry about stdio
streams).

If a process has any business closing stdio streams, it should
keep track of the handles (FILE *) for each open stream and use
them for this purpose.

Closing the standard streams can be a problem in some cases,
since for example it could remove all access to the controlling
terminal.



More information about the Comp.unix.wizards mailing list