Date: Sun, 19 Nov 2000 20:27:56 -0500 From: Garance A Drosihn <drosih@rpi.edu> To: hackers@FreeBSD.org Subject: fclose vs ferror (from libc/getcap) Message-ID: <p04330101b63e2c0b9192@[128.113.24.47]>
next in thread | raw e-mail | index | archive | help
As mentioned in pr bin/22965, I stumbled across a bug in libc/gen/getcap.c when compiling it under other platforms. The basic problem is some code which does: (void)fclose(pfp); if (ferror(pfp)) { ...do stuff... } I find it surprising that the above works under FreeBSD. (not only that, it seems to work OK under several other OS's too). The fclose is supposed to throw away the stream, but the ferror (apparently) still works with that pointer. The PR includes a patch for getcap.c (which is just to use the result from fclose to determine if an error occurred), but I also wonder if we should do something so that this combination would ALWAYS fail. It seems to me that fclose should clear out whatever fields that ferror is using for sanity-checking, and ferror should always return an errno of 'bad parameter', or something like that. Or is there some reason that we DO want ferror to work on streams which have already been closed? -- --- Garance Alistair Drosehn = gad@eclipse.acs.rpi.edu Senior Systems Programmer or gad@freebsd.org Rensselaer Polytechnic Institute or drosih@rpi.edu To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p04330101b63e2c0b9192>