cpython: 505bf6086ec5 (original) (raw)

Mercurial > cpython

changeset 95551:505bf6086ec5

Issue #23668: Adds support for os.truncate and os.ftruncate on Windows [#23668]

Steve Dower steve.dower@microsoft.com
date Fri, 20 Mar 2015 19:50:46 -0700
parents 1e64d57422ee
children 32652360d1c3
files Doc/library/io.rst Doc/library/os.rst Misc/NEWS Modules/_io/fileio.c Modules/posixmodule.c
diffstat 5 files changed, 57 insertions(+), 67 deletions(-)[+] [-] Doc/library/io.rst 7 Doc/library/os.rst 10 Misc/NEWS 2 Modules/_io/fileio.c 54 Modules/posixmodule.c 51

line wrap: on

line diff

--- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -339,8 +339,11 @@ I/O Base Classes if size is not specified). The current stream position isn't changed. This resizing can extend or reduce the current file size. In case of extension, the contents of the new file area depend on the platform

+

.. method:: writable()

--- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -805,8 +805,10 @@ as internal buffering of data. most length bytes in size. As of Python 3.3, this is equivalent to os.truncate(fd, length).

.. function:: get_blocking(fd) @@ -2492,10 +2494,12 @@ features: This function can support :ref:specifying a file descriptor <path_fd>.

.. function:: unlink(path, *, dir_fd=None)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -286,6 +286,8 @@ Library

--- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -839,9 +839,7 @@ static PyObject * fileio_truncate(fileio *self, PyObject *args) { PyObject posobj = NULL; / the new size wanted by the user */ -#ifndef MS_WINDOWS Py_off_t pos; -#endif int ret; int fd; @@ -864,52 +862,6 @@ fileio_truncate(fileio *self, PyObject * Py_INCREF(posobj); } -#ifdef MS_WINDOWS

-

-

-

-

-#else - #if defined(HAVE_LARGEFILE_SUPPORT) pos = PyLong_AsLongLong(posobj); #else @@ -922,11 +874,13 @@ fileio_truncate(fileio *self, PyObject * Py_BEGIN_ALLOW_THREADS errno = 0; +#ifdef MS_WINDOWS

+#else ret = ftruncate(fd, pos); +#endif Py_END_ALLOW_THREADS -#endif /* !MS_WINDOWS */ - if (ret != 0) { Py_DECREF(posobj); PyErr_SetFromErrno(PyExc_IOError);

--- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -2315,6 +2315,10 @@ FTRUNCATE #endif /[python end generated code: output=4bd4f6f7d41267f1 input=80b4c890b6774ea5]/ +#ifdef MS_WINDOWS

+#endif /*[python input] @@ -8753,7 +8757,7 @@ os_makedev_impl(PyModuleDef module, int #endif / HAVE_DEVICE_MACROS / -#ifdef HAVE_FTRUNCATE +#if defined HAVE_FTRUNCATE || defined MS_WINDOWS /[clinic input] os.ftruncate @@ -8771,9 +8775,16 @@ os_ftruncate_impl(PyModuleDef *module, i int result; int async_err = 0;

+ do { Py_BEGIN_ALLOW_THREADS +#ifdef MS_WINDOWS

+#else result = ftruncate(fd, length); +#endif Py_END_ALLOW_THREADS } while (result != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); @@ -8781,10 +8792,10 @@ os_ftruncate_impl(PyModuleDef module, i return (!async_err) ? posix_error() : NULL; Py_RETURN_NONE; } -#endif / HAVE_FTRUNCATE / - - -#ifdef HAVE_TRUNCATE +#endif / HAVE_FTRUNCATE || MS_WINDOWS / + + +#if defined HAVE_TRUNCATE || defined MS_WINDOWS /[clinic input] os.truncate path: path_t(allow_fd='PATH_HAVE_FTRUNCATE') @@ -8801,21 +8812,37 @@ os_truncate_impl(PyModuleDef module, pa /[clinic end generated code: output=f60a9e08370e9e2e input=77229cf0b50a9b77]*/ { int result; +#ifdef MS_WINDOWS

+#endif +

Py_BEGIN_ALLOW_THREADS -#ifdef HAVE_FTRUNCATE

+#ifdef MS_WINDOWS

+#else

+#endif Py_END_ALLOW_THREADS if (result < 0) return path_error(path); Py_RETURN_NONE; } -#endif /* HAVE_TRUNCATE / +#endif / HAVE_TRUNCATE || MS_WINDOWS / / Issue #22396: On 32-bit AIX platform, the prototypes of os.posix_fadvise() @@ -12771,7 +12798,7 @@ static char *have_functions[] = { "HAVE_FSTATVFS", #endif -#ifdef HAVE_FTRUNCATE +#if defined HAVE_FTRUNCATE || defined MS_WINDOWS "HAVE_FTRUNCATE", #endif