summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorJesus Cea <jcea@jcea.es>2012-06-22 16:32:07 (GMT)
committerJesus Cea <jcea@jcea.es>2012-06-22 16:32:07 (GMT)
commit9436361e4cdd7d3dc5f42674b54995c4915afb59 (patch)
tree18ecfd666aa3101811f6e79a5ca883293917a88b /Modules
parentff493c9c465ba9502629bf5001f690068be97f33 (diff)
downloadcpython-9436361e4cdd7d3dc5f42674b54995c4915afb59.zip
cpython-9436361e4cdd7d3dc5f42674b54995c4915afb59.tar.gz
cpython-9436361e4cdd7d3dc5f42674b54995c4915afb59.tar.bz2
Closes #10142: Support for SEEK_HOLE/SEEK_DATA
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/bufferedio.c21
-rw-r--r--Modules/posixmodule.c7
2 files changed, 25 insertions, 3 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 8a9ae47..dc723b1 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -1157,9 +1157,20 @@ buffered_seek(buffered *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O|i:seek", &targetobj, &whence)) {
return NULL;
}
- if (whence < 0 || whence > 2) {
+
+ /* Do some error checking instead of trusting OS 'seek()'
+ ** error detection, just in case.
+ */
+ if ((whence < 0 || whence >2)
+#ifdef SEEK_HOLE
+ && (whence != SEEK_HOLE)
+#endif
+#ifdef SEEK_DATA
+ && (whence != SEEK_DATA)
+#endif
+ ) {
PyErr_Format(PyExc_ValueError,
- "whence must be between 0 and 2, not %d", whence);
+ "whence value %d unsupported", whence);
return NULL;
}
@@ -1172,7 +1183,11 @@ buffered_seek(buffered *self, PyObject *args)
if (target == -1 && PyErr_Occurred())
return NULL;
- if (whence != 2 && self->readable) {
+ /* SEEK_SET and SEEK_CUR are special because we could seek inside the
+ buffer. Other whence values must be managed without this optimization.
+ Some Operating Systems can provide additional values, like
+ SEEK_HOLE/SEEK_DATA. */
+ if (((whence == 0) || (whence == 1)) && self->readable) {
Py_off_t current, avail;
/* Check if seeking leaves us inside the current buffer,
so as to return quickly if possible. Also, we needn't take the
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 094108a..5418cb9 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -11292,6 +11292,13 @@ all_ins(PyObject *d)
#endif
+#ifdef SEEK_HOLE
+ if (ins(d, "SEEK_HOLE", (long)SEEK_HOLE)) return -1;
+#endif
+#ifdef SEEK_DATA
+ if (ins(d, "SEEK_DATA", (long)SEEK_DATA)) return -1;
+#endif
+
/* MS Windows */
#ifdef O_NOINHERIT
/* Don't inherit in child processes. */