Skip to content

Commit 4799dad

Browse files
committed
bpo-37964: add F_GETPATH command in fcntl module
1 parent 8bf5fef commit 4799dad

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

Doc/library/fcntl.rst

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

36+
.. versionchanged:: 3.9
37+
The fcntl module now contains ``F_GETPATH`` constant, which will only be
38+
available in macos, and can be used to get path of a file from corresponfing
39+
file descriptor.
40+
3641
The module defines the following functions:
3742

3843

Lib/test/test_fcntl.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ 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+
s = '$'*len(abspath)
152+
res = fcntl.fcntl(self.f.fileno(), fcntl.F_GETPATH, s)
153+
self.assertEqual(abspath, res.decode('utf-8'))
154+
self.f.close()
147155

148156
def test_main():
149157
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 in fcntl module

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)