[ python-Bugs-1461855 ] fdopen() not guaranteed to have Python semantics
SourceForge.net
noreply at sourceforge.net
Fri Mar 31 18:20:13 CEST 2006
Bugs item #1461855, was opened at 2006-03-31 06:37
Message generated for change (Comment added) made by titty
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1461855&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: John Levon (movement)
Assigned to: Nobody/Anonymous (nobody)
Summary: fdopen() not guaranteed to have Python semantics
Initial Comment:
The specification for seek() says:
seek( offset[, whence])
Note that if the file is opened for appending (mode
'a' or 'a+'), any seek() operations will be undone at
the next write.
Consider operating on an fdopen()ed file. The Python
source simply calls into the OS-provided fdopen():
http://pxr.openlook.org/pxr/source/Modules/posixmodule.c#3530
However, the POSIX standard
http://www.opengroup.org/onlinepubs/009695399/functions/fdopen.html
says:
"Although not explicitly required by this volume of
IEEE Std 1003.1-2001, a good implementation of append
(a) mode would cause the O_APPEND flag to be set."
Thus, to ensure Python semantics, Python's fdopen()
must perform an fcntl() to ensure O_APPEND is set.
For example, on Solaris, this optional O_APPEND
behaviour is not applied:
http://cvs.opensolaris.org/source/xref/on/usr/src/lib/libc/port/stdio/fdopen.c?r=1.22#97
This has recently caused serious problems with the
Mercurial SCM.
----------------------------------------------------------------------
Comment By: Ralf Schmitt (titty)
Date: 2006-03-31 18:20
Message:
Logged In: YES
user_id=17929
freebsd 4.11 shows the same behaviour.
import fcntl
import os
def test_fdopen_append():
def is_append(fd):
return bool(fcntl.fcntl(fd, fcntl.F_GETFL) &
os.O_APPEND)
fd = os.open("foo.txt", os.O_RDWR | os.O_CREAT)
assert fd != -1
print "is_append:", is_append(fd)
f=os.fdopen(fd, 'a')
print "after fdopen is_append:", is_append(fd)
assert is_append(fd)
test_fdopen_append()
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1461855&group_id=5470
More information about the Python-bugs-list
mailing list