diff options
author | Brian Curtin <brian.curtin@gmail.com> | 2010-09-06 17:07:27 (GMT) |
---|---|---|
committer | Brian Curtin <brian.curtin@gmail.com> | 2010-09-06 17:07:27 (GMT) |
commit | 6285774f06f44f04353801cc79fd2a5e67f884ec (patch) | |
tree | fd38bd421fce735854ca6de4bbe0774ba0769fe8 /Modules/posixmodule.c | |
parent | 5c997b8d90e8e531bf844f5618a203f0a12ac9dc (diff) | |
download | cpython-6285774f06f44f04353801cc79fd2a5e67f884ec.zip cpython-6285774f06f44f04353801cc79fd2a5e67f884ec.tar.gz cpython-6285774f06f44f04353801cc79fd2a5e67f884ec.tar.bz2 |
Implement #7566 - os.path.sameopenfile for Windows.
This uses the GetFileInformationByHandle function to return a tuple of values
to identify a file, then ntpath.sameopenfile compares file tuples, which
is exposed as os.path.sameopenfile.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index dda758f..a83a06b 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -2758,6 +2758,33 @@ posix__getfinalpathname(PyObject *self, PyObject *args) return result; } /* end of posix__getfinalpathname */ + +static PyObject * +posix__getfileinformation(PyObject *self, PyObject *args) +{ + HANDLE hFile; + BY_HANDLE_FILE_INFORMATION info; + int fd; + + if (!PyArg_ParseTuple(args, "i:_getfileinformation", &fd)) + return NULL; + + if (!_PyVerify_fd(fd)) { + PyErr_SetString(PyExc_ValueError, "received invalid file descriptor"); + return NULL; + } + + hFile = (HANDLE)_get_osfhandle(fd); + if (hFile == INVALID_HANDLE_VALUE) + return win32_error("_getfileinformation", NULL); + + if (!GetFileInformationByHandle(hFile, &info)) + return win32_error("_getfileinformation", NULL); + + return Py_BuildValue("iii", info.dwVolumeSerialNumber, + info.nFileIndexHigh, + info.nFileIndexLow); +} #endif /* MS_WINDOWS */ PyDoc_STRVAR(posix_mkdir__doc__, @@ -7908,6 +7935,7 @@ static PyMethodDef posix_methods[] = { #ifdef MS_WINDOWS {"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL}, {"_getfinalpathname", posix__getfinalpathname, METH_VARARGS, NULL}, + {"_getfileinformation", posix__getfileinformation, METH_VARARGS, NULL}, #endif #ifdef HAVE_GETLOADAVG {"getloadavg", posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__}, |