Charles-François Natali <neolo...@free.fr> added the comment:
Patch attached.
> For lseek, we can rely on errno. Try something like that:
>
> errno = 0;
> offset = lseek(...);
> if (offset == (off_t)-1 && errno) /* error */
>
It's a little bit overkill :-) (for mktime, time_t can overflow easily
on 32-bit).
> We can write a test using a sparse file... Or maybe a mmap object?
>
I'm not sure it's easily testable, because it's really a corner case
not addressed by POSIX. On my Linux box, I can't get lseek to return a
negative value, I get EINVAL - which does make sense (the Linux kernel
doesn't accept or return negative file offsets, see
http://lwn.net/Articles/138063/).
Kuberan, on what operating system did you notice this problem? Solaris?
----------
keywords: +patch
Added file: http://bugs.python.org/file22719/lseek_negative.diff
_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12545>
_______________________________________
diff -r d3f0f72c31f8 Modules/_io/fileio.c
--- a/Modules/_io/fileio.c Fri Jul 22 11:10:43 2011 -0500
+++ b/Modules/_io/fileio.c Fri Jul 22 22:33:54 2011 +0200
@@ -823,7 +823,7 @@
Py_END_ALLOW_THREADS
} else
res = -1;
- if (res < 0)
+ if (res == -1)
return PyErr_SetFromErrno(PyExc_IOError);
#if defined(HAVE_LARGEFILE_SUPPORT)
diff -r d3f0f72c31f8 Modules/posixmodule.c
--- a/Modules/posixmodule.c Fri Jul 22 11:10:43 2011 -0500
+++ b/Modules/posixmodule.c Fri Jul 22 22:33:54 2011 +0200
@@ -6257,7 +6257,7 @@
res = lseek(fd, pos, how);
#endif
Py_END_ALLOW_THREADS
- if (res < 0)
+ if (res == -1)
return posix_error();
#if !defined(HAVE_LARGEFILE_SUPPORT)
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com