KSH portability (fd to FILE *)

chris at mimsy.UUCP chris at mimsy.UUCP
Sat May 21 13:07:54 AEST 1988


In article <15200005 at bucc2> brian at bucc2.UUCP writes:
>  Won't
>
>FILE *fdtofp(int fd) { return &_iob[fd] };
>
>  work? Look at stdio.h...

It will not work.  Look at stdio.h, and then look at another stdio.h,
and make sure one is a 4.3BSD stdio.h....

Even in older stdios, _iob[k]._file is not necessarily k: fdopen,
or assignments to fileno(fp) [gack], might make them unequal; and
I am almost certain that a successful open followed immediately
by a successful fopen will make them unequal.

>>What is *really* needed is an array of FILE**, maintained by stdio so
>>that one could do:
>> 	for (i = 0; i < FILEMAX; i++)
>> 		if (FILES[i]) do_something_with(FILES[i]);
>>[Root Boy Jim]

>	for (i = 0; i < _NFILE; i++)
>		if (???) do_something_with(&_iobuf[i]);

Newer <stdio.h>s do not even define _NFILE.  4.3BSD has an array of 20
static _iob's, and dynamically allocates the rest and glues them
together with private data.  The array of static _iob's exists only
because too many programs broke without it.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.wizards mailing list