This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: f.flush() fails on FreeBSD 5.2
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: hsn, loewis
Priority: normal Keywords:

Created on 2004-04-08 18:20 by hsn, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg20454 - (view) Author: Radim Kolar (hsn) Date: 2004-04-08 18:20
Hi,
 if you open file for read-only and want to flush() it, it fails on freebsd5.2.
 It works okay on linux. If file is openned for r/w it works on freebsd.

     
f=file("/etc/passwd","r")
f.read(10)
f.flush()
f.close()

result:
(hsn@ttyv2):~% python snakeoil.py
Traceback (most recent call last):
  File "snakeoil.py", line 3, in ?
      f.flush()
      IOError: [Errno 9] Bad file descriptor
msg20455 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2004-04-08 21:48
Logged In: YES 
user_id=21627

In C, flushing a file that was opened for read only causes
undefined behaviour. So it is not surprising that systems
behave differently in this respect.
msg20456 - (view) Author: Radim Kolar (hsn) Date: 2004-04-09 16:37
Logged In: YES 
user_id=590679

I have wrote a simple program which calls fsync() on file opened for readonly. Test programs works okay (no error) on both platforms (FreeBSD and Linux). So error is not in FreeBSD5 kernel.
msg20457 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2004-04-09 21:49
Logged In: YES 
user_id=21627

Can you please also try a program that uses fflush, like the
Python program does:
fopen("/etc/passwd","r");
fread(buf, 10, 1, f);
fflush(f); /* check errno here */
fclose(f);
msg20458 - (view) Author: Radim Kolar (hsn) Date: 2004-04-10 17:23
Logged In: YES 
user_id=590679

fflush() on readonly file fails in freebsd5, because libc checks this case.

This is bug in freebsd libc.  I have submited bug report with patch to freebsd
team.
msg20459 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2004-04-11 22:11
Logged In: YES 
user_id=21627

As I explained earlier, according to C99, invoking fflush on
a stream opened for read only causes undefined behaviour. So
FreeBSD is conforming to the spec by reporting an error, and
Python follows its documentation and its spirit by passing
that error report to the user.

So closing the report as invalid.
History
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 40130
2004-04-08 18:20:59hsncreate