Jaakko Moisio added the comment: Thank you for your comments.
> I was a little surprised when Jaako says that ferror() is enough to > detect this, so I modified Serhiy code to print ferror(), and actually > ferror() reports an error for subsequent writes, not for the first one > (probably because the error goes unnoticed only when the buffer is in > a particular state). Strange. I too modified Serchiy's code and my version of glibc (2.15) set the error flag at the same fwrite call as errno was set: setvbuf 0 0 0 fwrite 5 0 0 fwrite 1 28 1 fwrite 1 28 1 (the last column being the return value of ferror after each fwrite call) I've trusted ferror until now but I'm not an expert on the subject. It's a good point that errno is set by the underlying system call and is thus more reliable. So would checking errno be sufficient (in addition to checking that the lengths agree)? It can only serve to make file_write more robust. ---------- Added file: http://bugs.python.org/file30260/fileobject-fix2.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17976> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com