Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2630,6 +2630,11 @@ features:
Compose a raw device number from the major and minor device numbers.


.. data:: NODEV

Non-existent device.


.. function:: pathconf(path, name)

Return system configuration information relevant to a named file. *name*
Expand Down
15 changes: 13 additions & 2 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,23 @@ def test_makedev(self):
self.assertRaises((ValueError, OverflowError), posix.makedev, x, minor)
self.assertRaises((ValueError, OverflowError), posix.makedev, major, x)

if sys.platform == 'linux' and not support.linked_to_musl():
NODEV = -1
if (hasattr(posix, 'NODEV') and
sys.platform.startswith(('linux', 'macos', 'freebsd', 'dragonfly',
'sunos'))):
NODEV = posix.NODEV
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code path still skipped on Alpine Linux (musl)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is skipped if NODEV is not defined in musl. But if it is defined, the following tests will fail, so we will need to add an additional condition.

self.assertEqual(posix.major(NODEV), NODEV)
self.assertEqual(posix.minor(NODEV), NODEV)
self.assertEqual(posix.makedev(NODEV, NODEV), NODEV)

def test_nodev(self):
if (not hasattr(posix, 'NODEV')
and (not sys.platform.startswith(('linux', 'macos', 'freebsd',
'dragonfly', 'netbsd', 'openbsd',
'sunos'))
or support.linked_to_musl())):
self.skipTest('not defined on this platform')
self.assertHasAttr(posix, 'NODEV')

def _test_all_chown_common(self, chown_func, first_param, stat_func):
"""Common code for chown, fchown and lchown tests."""
def check_stat(uid, gid):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add :const:`os.NODEV`.
6 changes: 5 additions & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2759,7 +2759,7 @@ _pystat_fromstructstat(PyObject *module, STRUCT_STAT *st)
SET_ITEM(ST_BLOCKS_IDX, PyLong_FromLong((long)st->st_blocks));
#endif
#ifdef HAVE_STRUCT_STAT_ST_RDEV
SET_ITEM(ST_RDEV_IDX, PyLong_FromLong((long)st->st_rdev));
SET_ITEM(ST_RDEV_IDX, _PyLong_FromDev(st->st_rdev));
#endif
#ifdef HAVE_STRUCT_STAT_ST_GEN
SET_ITEM(ST_GEN_IDX, PyLong_FromLong((long)st->st_gen));
Expand Down Expand Up @@ -17878,6 +17878,10 @@ all_ins(PyObject *m)
#endif
#endif /* HAVE_EVENTFD && EFD_CLOEXEC */

#ifdef NODEV
if (PyModule_Add(m, "NODEV", _PyLong_FromDev(NODEV))) return -1;
#endif

#if defined(__APPLE__)
if (PyModule_AddIntConstant(m, "_COPYFILE_DATA", COPYFILE_DATA)) return -1;
if (PyModule_AddIntConstant(m, "_COPYFILE_STAT", COPYFILE_STAT)) return -1;
Expand Down
Loading