mirror of
https://github.com/python/cpython.git
synced 2025-10-29 17:38:56 +00:00
See SF# 1751801: Windows: Add the _fileio builtin module, and undefine
HAVE_FTRUNCATE because ftruncate does not exist on Windows.
This commit is contained in:
parent
9004427589
commit
c6a55ee2a5
3 changed files with 12 additions and 1 deletions
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
/* can simulate truncate with Win32 API functions; see file_truncate */
|
/* can simulate truncate with Win32 API functions; see file_truncate */
|
||||||
#define HAVE_FTRUNCATE
|
/* #define HAVE_FTRUNCATE */
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -581,6 +581,7 @@ fileio_tell(PyFileIOObject *self, PyObject *args)
|
||||||
return portable_lseek(self->fd, NULL, 1);
|
return portable_lseek(self->fd, NULL, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_FTRUNCATE
|
||||||
static PyObject *
|
static PyObject *
|
||||||
fileio_truncate(PyFileIOObject *self, PyObject *args)
|
fileio_truncate(PyFileIOObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
|
@ -629,6 +630,7 @@ fileio_truncate(PyFileIOObject *self, PyObject *args)
|
||||||
|
|
||||||
return posobj;
|
return posobj;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
mode_string(PyFileIOObject *self)
|
mode_string(PyFileIOObject *self)
|
||||||
|
|
@ -711,10 +713,12 @@ PyDoc_STRVAR(seek_doc,
|
||||||
"\n"
|
"\n"
|
||||||
"Note that not all file objects are seekable.");
|
"Note that not all file objects are seekable.");
|
||||||
|
|
||||||
|
#ifdef HAVE_FTRUNCATE
|
||||||
PyDoc_STRVAR(truncate_doc,
|
PyDoc_STRVAR(truncate_doc,
|
||||||
"truncate([size: int]) -> None. Truncate the file to at most size bytes.\n"
|
"truncate([size: int]) -> None. Truncate the file to at most size bytes.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Size defaults to the current file position, as returned by tell().");
|
"Size defaults to the current file position, as returned by tell().");
|
||||||
|
#endif
|
||||||
|
|
||||||
PyDoc_STRVAR(tell_doc,
|
PyDoc_STRVAR(tell_doc,
|
||||||
"tell() -> int. Current file position");
|
"tell() -> int. Current file position");
|
||||||
|
|
@ -747,7 +751,9 @@ static PyMethodDef fileio_methods[] = {
|
||||||
{"write", (PyCFunction)fileio_write, METH_VARARGS, write_doc},
|
{"write", (PyCFunction)fileio_write, METH_VARARGS, write_doc},
|
||||||
{"seek", (PyCFunction)fileio_seek, METH_VARARGS, seek_doc},
|
{"seek", (PyCFunction)fileio_seek, METH_VARARGS, seek_doc},
|
||||||
{"tell", (PyCFunction)fileio_tell, METH_VARARGS, tell_doc},
|
{"tell", (PyCFunction)fileio_tell, METH_VARARGS, tell_doc},
|
||||||
|
#ifdef HAVE_FTRUNCATE
|
||||||
{"truncate", (PyCFunction)fileio_truncate, METH_VARARGS, truncate_doc},
|
{"truncate", (PyCFunction)fileio_truncate, METH_VARARGS, truncate_doc},
|
||||||
|
#endif
|
||||||
{"close", (PyCFunction)fileio_close, METH_NOARGS, close_doc},
|
{"close", (PyCFunction)fileio_close, METH_NOARGS, close_doc},
|
||||||
{"seekable", (PyCFunction)fileio_seekable, METH_NOARGS, seekable_doc},
|
{"seekable", (PyCFunction)fileio_seekable, METH_NOARGS, seekable_doc},
|
||||||
{"readable", (PyCFunction)fileio_readable, METH_NOARGS, readable_doc},
|
{"readable", (PyCFunction)fileio_readable, METH_NOARGS, readable_doc},
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ extern void init_subprocess(void);
|
||||||
extern void init_lsprof(void);
|
extern void init_lsprof(void);
|
||||||
extern void init_ast(void);
|
extern void init_ast(void);
|
||||||
extern void init_types(void);
|
extern void init_types(void);
|
||||||
|
extern void init_fileio(void);
|
||||||
|
|
||||||
/* tools/freeze/makeconfig.py marker for additional "extern" */
|
/* tools/freeze/makeconfig.py marker for additional "extern" */
|
||||||
/* -- ADDMODULE MARKER 1 -- */
|
/* -- ADDMODULE MARKER 1 -- */
|
||||||
|
|
@ -145,6 +146,7 @@ struct _inittab _PyImport_Inittab[] = {
|
||||||
{"sys", NULL},
|
{"sys", NULL},
|
||||||
|
|
||||||
{"_types", init_types},
|
{"_types", init_types},
|
||||||
|
{"_fileio", init_fileio},
|
||||||
|
|
||||||
/* Sentinel */
|
/* Sentinel */
|
||||||
{0, 0}
|
{0, 0}
|
||||||
|
|
|
||||||
|
|
@ -370,6 +370,9 @@
|
||||||
<File
|
<File
|
||||||
RelativePath="..\Modules\_csv.c">
|
RelativePath="..\Modules\_csv.c">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\Modules\_fileio.c">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\Modules\_functoolsmodule.c">
|
RelativePath="..\Modules\_functoolsmodule.c">
|
||||||
</File>
|
</File>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue