Messages in this thread | | | Date | Thu, 18 Dec 1997 19:12:57 +0100 | From | Pavel Machek <> | Subject | Re: Write to a closed stream bug. |
| |
Hi!
> > And: It behaved incorrectly: you gave it some invalid handle. It did > > not *write* anywhere. If you passed invalid handle, that was valid > > enough for data to go *somewhere*, returning success would be > > acceptable. > > Imagine the following code: > > 1: FILE *s1, *s2; > 2: > 3: s1 = fopen ("foo", "rw"); /* s1 gets assigned */ > 4: fwrite ("Hello", 1, 5, s1); > 5: fclose (s1); /* after this, the system is > 6: free to do whatever it wants > 7: with the memory pointed to > 8: by s1 */ > 9: s2 = fopen ("bar", "rw"); /* actually, it gets assigned > 10: to s2, so s1 and s2 now > 11: refer to the same memory */ > 12: fwrite ("World", 1, 5, s1); /* Ooops, s1 now writes to > file bar!!!! */
Which is completely Ok for me. If data really go somewhere, than that's application programmers bug. But if data are silently discarded, library function should inform user of that.
> So there is no way to get a deterministic behaviour when > passing an fclosed stream to a function and glibc is free > to return whatever it wants (including success). A program > doing such things is buggy and cannot expect anything useful > from libc.
I do not want deterministic behaviour. I just want library function to tell when error happens. Writing to a wrong file is not error. Not writing at all is.
Pavel -- I'm really pavel@atrey.karlin.mff.cuni.cz. Pavel Look at http://atrey.karlin.mff.cuni.cz/~pavel/ ;-).
| |