summaryrefslogtreecommitdiffstats
path: root/Objects/fileobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-05-05 22:15:02 (GMT)
committerGuido van Rossum <guido@python.org>1997-05-05 22:15:02 (GMT)
commitfdf95dd525840559d77637802ff117969db19031 (patch)
treeac06e548154ef068d134401a08f66c17d681628b /Objects/fileobject.c
parent8290e075096ac985c564b738a35307fac0992149 (diff)
downloadcpython-fdf95dd525840559d77637802ff117969db19031.zip
cpython-fdf95dd525840559d77637802ff117969db19031.tar.gz
cpython-fdf95dd525840559d77637802ff117969db19031.tar.bz2
Checkin of Jack's buffer mods.
Not really checked, but didn't fail any tests either...
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r--Objects/fileobject.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index cee41a10..a4b1d4b 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -419,6 +419,41 @@ file_read(f, args)
return v;
}
+static PyObject *
+file_readinto(f, args)
+ PyFileObject *f;
+ PyObject *args;
+{
+ char *ptr;
+ int ntodo, ndone, nnow;
+
+ if (f->f_fp == NULL)
+ return err_closed();
+ if (!PyArg_Parse(args, "w#", &ptr, &ntodo))
+ return NULL;
+ ndone = 0;
+ /*
+ ** XXXX Is this correct? Other threads may see partially-completed
+ ** reads if they look at the object we're reading into...
+ */
+ Py_BEGIN_ALLOW_THREADS
+ while(ntodo > 0) {
+ nnow = fread(ptr+ndone, 1, ntodo, f->f_fp);
+ if (nnow < 0 ) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ clearerr(f->f_fp);
+ return NULL;
+ }
+ if (nnow == 0)
+ break;
+ ndone += nnow;
+ ntodo -= nnow;
+ }
+ Py_END_ALLOW_THREADS
+ return PyInt_FromLong(ndone);
+}
+
+
/* Internal routine to get a line.
Size argument interpretation:
> 0: max length;
@@ -688,6 +723,7 @@ static PyMethodDef file_methods[] = {
{"tell", (PyCFunction)file_tell, 0},
{"write", (PyCFunction)file_write, 0},
{"writelines", (PyCFunction)file_writelines, 0},
+ {"readinto", (PyCFunction)file_readinto, 0},
{NULL, NULL} /* sentinel */
};