New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong tell() result for a file opened in append mode #49258
Comments
The following code must display 3 instead of 0: with open("x", "w") as f:
f.write("xxx")
with open("x", "a") as f:
print(f.tell()) The example works with Python 2.x, because file object is implemented import os
with open("x", "w") as f:
f.write("xxx")
fd = os.open("x", os.O_RDONLY | os.O_APPEND)
print(os.lseek(fd, 0, 1)) display 0 instead of 3 on Python 2.x and 3.x. It becomes a little bit more weird when you write something :-) with open("x", "w") as f:
f.write("xxx")
with open("x", "a") as f:
f.write("y")
print(f.tell()) displays... 4 (the correct position) on Python 2.x and 3.x. I see (in GNU libc source code) that fopen() call lseek(fd, 0, |
Patch _including a test_: + if (append) |
Comments on the patch:
|
Patch version 2:
I use the type "long" to store the lseek() result, because I don't |
Instead of checking the return type, you can first set errno to 0, and
Nice catch! http://bugs.python.org/issue5016 PS : about the patch, "0 < f.tell()" is really strange coding style... |
Last thing, in your patch there is a forward declaration to |
New try (version 3):
This patch also prepares a fix for bpo-5016. |
Version 4: ok, let's use *portable*_lseek() instead of the "ugly" |
Committed in r68835, r68836, r68837, r68838. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: