]> granicus.if.org Git - python/commitdiff
closes bpo-37964: add F_GETPATH command to fcntl (GH-15550)
authorVinay Sharma <vinay04sharma@icloud.com>
Thu, 29 Aug 2019 01:56:17 +0000 (07:26 +0530)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 29 Aug 2019 01:56:17 +0000 (18:56 -0700)
https://bugs.python.org/issue37964

Automerge-Triggered-By: @benjaminp
Doc/library/fcntl.rst
Lib/test/test_fcntl.py
Misc/NEWS.d/next/Library/2019-08-27-21-19-28.bpo-37964.SxdnsF.rst [new file with mode: 0644]
Modules/fcntlmodule.c

index 2db9674952d7b66baba19c02585f0b6e63b10614..6a66f5b664811bd3132123a65bed4dfb55cc1d69 100644 (file)
@@ -33,6 +33,10 @@ descriptor.
    ``F_SEAL_*`` constants for sealing of :func:`os.memfd_create` file
    descriptors.
 
+.. versionchanged:: 3.9
+   On macOS, the fcntl module exposes the ``F_GETPATH`` constant, which obtains
+   the path of a file from a file descriptor.
+
 The module defines the following functions:
 
 
index 5d4abe388f78287b69be451b8651d377c7e89a67..38097dbdfb97e456de73025df1f2efcf54545171 100644 (file)
@@ -144,6 +144,12 @@ class TestFcntl(unittest.TestCase):
         self.assertRaises(OverflowError, fcntl.flock, _testcapi.INT_MAX+1,
                           fcntl.LOCK_SH)
 
+    @unittest.skipIf(sys.platform != 'darwin', "F_GETPATH is only available on macos")
+    def test_fcntl_f_getpath(self):
+        self.f = open(TESTFN, 'wb')
+        abspath = os.path.abspath(TESTFN)
+        res = fcntl.fcntl(self.f.fileno(), fcntl.F_GETPATH, bytes(len(abspath)))
+        self.assertEqual(abspath, res.decode('utf-8'))
 
 def test_main():
     run_unittest(TestFcntl)
diff --git a/Misc/NEWS.d/next/Library/2019-08-27-21-19-28.bpo-37964.SxdnsF.rst b/Misc/NEWS.d/next/Library/2019-08-27-21-19-28.bpo-37964.SxdnsF.rst
new file mode 100644 (file)
index 0000000..c25e643
--- /dev/null
@@ -0,0 +1 @@
+Add ``F_GETPATH`` command to :mod:`fcntl`.
index 0fbf7876c3e207a2815ca497cc89830b1f982d21..cfa1225684049f27b8427526084b4891bddefff6 100644 (file)
@@ -501,6 +501,9 @@ all_ins(PyObject* m)
 #ifdef F_SETOWN
     if (PyModule_AddIntMacro(m, F_SETOWN)) return -1;
 #endif
+#ifdef F_GETPATH
+    if (PyModule_AddIntMacro(m, F_GETPATH)) return -1;
+#endif
 #ifdef F_GETSIG
     if (PyModule_AddIntMacro(m, F_GETSIG)) return -1;
 #endif