Skip to content

Commit 13f37f2

Browse files
vinay0410miss-islington
authored andcommitted
closes bpo-37964: add F_GETPATH command to fcntl (GH-15550)
https://bugs.python.org/issue37964 Automerge-Triggered-By: @benjaminp
1 parent e4a5e9b commit 13f37f2

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

Doc/library/fcntl.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ descriptor.
3333
``F_SEAL_*`` constants for sealing of :func:`os.memfd_create` file
3434
descriptors.
3535

36+
.. versionchanged:: 3.9
37+
On macOS, the fcntl module exposes the ``F_GETPATH`` constant, which obtains
38+
the path of a file from a file descriptor.
39+
3640
The module defines the following functions:
3741

3842

Lib/test/test_fcntl.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ def test_flock_overflow(self):
144144
self.assertRaises(OverflowError, fcntl.flock, _testcapi.INT_MAX+1,
145145
fcntl.LOCK_SH)
146146

147+
@unittest.skipIf(sys.platform != 'darwin', "F_GETPATH is only available on macos")
148+
def test_fcntl_f_getpath(self):
149+
self.f = open(TESTFN, 'wb')
150+
abspath = os.path.abspath(TESTFN)
151+
res = fcntl.fcntl(self.f.fileno(), fcntl.F_GETPATH, bytes(len(abspath)))
152+
self.assertEqual(abspath, res.decode('utf-8'))
147153

148154
def test_main():
149155
run_unittest(TestFcntl)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``F_GETPATH`` command to :mod:`fcntl`.

Modules/fcntlmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ all_ins(PyObject* m)
501501
#ifdef F_SETOWN
502502
if (PyModule_AddIntMacro(m, F_SETOWN)) return -1;
503503
#endif
504+
#ifdef F_GETPATH
505+
if (PyModule_AddIntMacro(m, F_GETPATH)) return -1;
506+
#endif
504507
#ifdef F_GETSIG
505508
if (PyModule_AddIntMacro(m, F_GETSIG)) return -1;
506509
#endif

0 commit comments

Comments
 (0)