diff -r 9725ddcd37e6 Doc/library/os.rst --- a/Doc/library/os.rst Sun Jun 24 11:57:07 2012 +0200 +++ b/Doc/library/os.rst Sun Jun 24 12:17:33 2012 +0200 @@ -1629,6 +1629,9 @@ features: included in ``pathconf_names``, an :exc:`OSError` is raised with :const:`errno.EINVAL` for the error number. + This function can support :ref:`specifying an open file descriptor + `. + Availability: Unix. diff -r 9725ddcd37e6 Lib/os.py --- a/Lib/os.py Sun Jun 24 11:57:07 2012 +0200 +++ b/Lib/os.py Sun Jun 24 12:17:33 2012 +0200 @@ -174,6 +174,7 @@ if _exists("_have_functions"): _set.add(stat) # fstat always works _add("HAVE_FUTIMENS", "utime") _add("HAVE_FUTIMES", "utime") + _add("HAVE_FPATHCONF", "pathconf") if _exists("statvfs") and _exists("fstatvfs"): # mac os x10.3 _add("HAVE_FSTATVFS", "statvfs") supports_fd = _set diff -r 9725ddcd37e6 Modules/posixmodule.c --- a/Modules/posixmodule.c Sun Jun 24 11:57:07 2012 +0200 +++ b/Modules/posixmodule.c Sun Jun 24 12:17:33 2012 +0200 @@ -9219,31 +9219,45 @@ posix_fpathconf(PyObject *self, PyObject PyDoc_STRVAR(posix_pathconf__doc__, "pathconf(path, name) -> integer\n\n\ Return the configuration limit name for the file or directory path.\n\ -If there is no limit, return -1."); - -static PyObject * -posix_pathconf(PyObject *self, PyObject *args) -{ +If there is no limit, return -1.\n\ +On some platforms, path may also be specified as an open file descriptor.\n\ + If this functionality is unavailable, using it raises an exception."); + +static PyObject * +posix_pathconf(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; PyObject *result = NULL; int name; - char *path; - - if (PyArg_ParseTuple(args, "sO&:pathconf", &path, - conv_path_confname, &name)) { + static char *keywords[] = {"path", "name", NULL}; + + memset(&path, 0, sizeof(path)); +#ifdef HAVE_FPATHCONF + path.allow_fd = 1; +#endif + if (PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&:pathconf", keywords, + path_converter, &path, + conv_path_confname, &name)) { long limit; errno = 0; - limit = pathconf(path, name); +#ifdef HAVE_FPATHCONF + if (path.fd != -1) + limit = fpathconf(path.fd, name); + else +#endif + limit = pathconf(path.narrow, name); if (limit == -1 && errno != 0) { if (errno == EINVAL) /* could be a path or name problem */ posix_error(); else - posix_error_with_filename(path); + result = path_error("pathconf", &path); } else result = PyLong_FromLong(limit); } + path_cleanup(&path); return result; } #endif @@ -11149,7 +11163,9 @@ static PyMethodDef posix_methods[] = { {"fpathconf", posix_fpathconf, METH_VARARGS, posix_fpathconf__doc__}, #endif #ifdef HAVE_PATHCONF - {"pathconf", posix_pathconf, METH_VARARGS, posix_pathconf__doc__}, + {"pathconf", (PyCFunction)posix_pathconf, + METH_VARARGS | METH_KEYWORDS, + posix_pathconf__doc__}, #endif {"abort", posix_abort, METH_NOARGS, posix_abort__doc__}, #ifdef MS_WINDOWS @@ -11741,6 +11757,10 @@ static char *have_functions[] = { "HAVE_FDOPENDIR", #endif +#ifdef HAVE_FPATHCONF + "HAVE_FPATHCONF", +#endif + #ifdef HAVE_FSTATAT "HAVE_FSTATAT", #endif