Re: Closing the FILE object.

From: Richard B. Johnson (root@chaos.analogic.com)
Date: Fri Jul 14 2000 - 15:52:50 EST


On Fri, 14 Jul 2000, Jesse Pollard wrote:
[Snipped...]
>
> Yes, No and I understand.
>
> AT&T System V had stdin/stdout/stderr defined as if the following were used:
>
> const FILE *stdin = &STDIN;
>
> static FILE STDIN = {....};
>
> This ment that the default stdin/stdout.... were constants and could not
> be modified.
>
> HOWEVER, the release 2 manpage suggested that for portability all
> I/O should go through a file pointer defined as:
>
> FILE *input = stdin;
>
> Then you COULD replace the default input by
>
> altinput = fopen(...);
> input = altinput;
>
> The other note is that the manpage goes back to BSD in 1993. I don't think
> the library functions implimenting fopen/fclose ... have remained the same.
>
> At the time the man page was written the standard I/O library created the
> file pointer from something like:
>
>
> static FILE io[MAXFILECOUNT];
> static int nextfile = 0;
>
> ....
> FILE * fopen(char *path, char * mode)
> {
> ...
> initialization for io[nextfile]
> io[nextfile] = open(path, intflags);
> ...
> if (io[nextfile] >= 0)
> return(&io[nextfile++]);
> return(NULL);
> }
>
> This allows the manpage to be correct, since the structure pointed to by
> the FILE * variable is never deallocated. It is also NOT thread safe.
>
> ALSO NOTE - this does not conflict with the "const FILE *stdin.." shown
> earlier. stdin/stdout/stderr were not part of this array.
>
> I don't think stdio library works that way anymore.
>
> MAXFILECOUNT was 16 to 32 at the time, and multi-threaded I/O did not exist.
>
> I think the manpage needs to be rewritten.
>

Yes. You state the history well. I brought up this whole can-of-worms
again (in spite of extreme peril to flame-throwers) because there are
some important holes in the current documentation and some ignored
implementation details. For instance, Unix System-V release 2.0,
my first "Unix system", documentation released in 1983, states that
FCLOSE(3S) should return EOF on an error. In never mentions errno.

Of course in those days if you got your program to compile, you were
done.

Cheers,
Dick Johnson

Penguin : Linux version 2.2.15 on an i686 machine (797.90 BogoMips).

"Memory is like gasoline. You use it up when you are running. Of
course you get it all back when you reboot..."; Actual explanation
obtained from the Micro$oft help desk.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Jul 15 2000 - 21:00:20 EST