Skip to content

closes bpo-37964: add F_GETPATH command to fcntl #15550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Doc/library/fcntl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:


Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_fcntl.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ def test_flock_overflow(self):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``F_GETPATH`` command to :mod:`fcntl`.
3 changes: 3 additions & 0 deletions Modules/fcntlmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down