Skip to content

Commit 15468a7

Browse files
committed
gh-85264: Expose DEV_BSIZE from posixmodule.c
https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 2e64e36 commit 15468a7

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Doc/library/os.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,16 @@ features:
26632663
.. versionadded:: 3.15
26642664

26652665

2666+
.. data:: DEV_BSIZE
2667+
2668+
The size, in bytes, of a block as reported by the :attr:`~os.stat_result.st_blocks`
2669+
field of :class:`~os.stat_result`. This is typically 512 bytes.
2670+
2671+
:ref:`Availability <availability>`: Unix.
2672+
2673+
.. versionadded:: 3.15
2674+
2675+
26662676
.. function:: pathconf(path, name)
26672677

26682678
Return system configuration information relevant to a named file. *name*

Modules/posixmodule.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18393,6 +18393,17 @@ all_ins(PyObject *m)
1839318393
/* STATX_ATTR_* constants are in the stat module */
1839418394
#endif /* HAVE_STATX */
1839518395

18396+
/* Block size for the st_blocks field of stat(2).
18397+
* st_blocks is in 512-byte units on most platforms. DEV_BSIZE (or BSIZE
18398+
* as a fallback) from sys/param.h gives the actual platform value. */
18399+
#if defined(HAVE_STRUCT_STAT_ST_BLOCKS)
18400+
# if defined(DEV_BSIZE)
18401+
if (PyModule_AddIntConstant(m, "DEV_BSIZE", DEV_BSIZE)) return -1;
18402+
# elif defined(BSIZE)
18403+
if (PyModule_AddIntConstant(m, "DEV_BSIZE", BSIZE)) return -1;
18404+
# endif
18405+
#endif
18406+
1839618407
#if defined(__APPLE__)
1839718408
if (PyModule_AddIntConstant(m, "_COPYFILE_DATA", COPYFILE_DATA)) return -1;
1839818409
if (PyModule_AddIntConstant(m, "_COPYFILE_STAT", COPYFILE_STAT)) return -1;

0 commit comments

Comments
 (0)