From 4af8d6a0e574ea39b65517cfcb198d7d81e03d65 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 17 Jan 2025 22:32:58 +0100 Subject: [PATCH] sys_types-h: Ensure blksize_t and blkcnt_t are defined. * lib/sys_types.in.h (blksize_t, blkcnt_t): New definitions. * m4/sys_types_h.m4 (gl_SYS_TYPES_H): Set HAVE_BLKSIZE_T and HAVE_BLKCNT_T. * modules/sys_types-h (Makefile.am): Substitute HAVE_BLKSIZE_T and HAVE_BLKCNT_T. * tests/test-sys_types-h.c: Check that blksize_t and blkcnt_t are defined. Include intprops.h. Check the signedness of various types. * modules/sys_types-h-tests (Depends-on): Add assert-h, intprops. * doc/posix-headers/sys_types.texi: Mention the issues with blksize_t and blkcnt_t. --- ChangeLog | 14 ++++++++++++++ doc/posix-headers/sys_types.texi | 9 +++++++++ lib/sys_types.in.h | 16 ++++++++++++++++ m4/sys_types_h.m4 | 10 +++++++++- modules/sys_types-h | 2 ++ modules/sys_types-h-tests | 2 ++ tests/test-sys_types-h.c | 29 ++++++++++++++++++++++++++++- 7 files changed, 80 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5796c80ae0..8b77cac9ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2025-01-17 Bruno Haible + + sys_types-h: Ensure blksize_t and blkcnt_t are defined. + * lib/sys_types.in.h (blksize_t, blkcnt_t): New definitions. + * m4/sys_types_h.m4 (gl_SYS_TYPES_H): Set HAVE_BLKSIZE_T and + HAVE_BLKCNT_T. + * modules/sys_types-h (Makefile.am): Substitute HAVE_BLKSIZE_T and + HAVE_BLKCNT_T. + * tests/test-sys_types-h.c: Check that blksize_t and blkcnt_t are + defined. Include intprops.h. Check the signedness of various types. + * modules/sys_types-h-tests (Depends-on): Add assert-h, intprops. + * doc/posix-headers/sys_types.texi: Mention the issues with blksize_t + and blkcnt_t. + 2025-01-17 Paul Eggert crc-x86_64: port to old GCC compilers diff --git a/doc/posix-headers/sys_types.texi b/doc/posix-headers/sys_types.texi index 2684e23a58..ed301c4b2c 100644 --- a/doc/posix-headers/sys_types.texi +++ b/doc/posix-headers/sys_types.texi @@ -24,6 +24,12 @@ MSVC 14. The type @code{off64_t} is not defined on some platforms: macOS 14, FreeBSD 10.4, NetBSD 10.0, OpenBSD 7.5, MSVC 14, Cygwin, Haiku, Minix 3.3. @item +The type @code{blksize_t} is not defined on some platforms: +FreeBSD 5.5, OpenBSD 5.6, HP-UX 11.23, IRIX 6.5, mingw, MSVC 14. +@item +The type @code{blkcnt_t} is not defined on some platforms: +FreeBSD 5.5, OpenBSD 5.6, mingw, MSVC 14. +@item Some systems leak definitions of @code{major}, @code{minor}, and @code{makedev} through this header; however, when @file{sys/sysmacros.h} exists, that file should also be included to @@ -37,6 +43,9 @@ glibc 2.25. Portability problems not fixed by Gnulib: @itemize @item +On some platforms the types @code{blksize_t} and @code{blkcnt_t} are unsigned: +Android. +@item On some platforms the types @code{blksize_t} and @code{suseconds_t} are signed integer types that are wider than @code{long}: glibc x32 diff --git a/lib/sys_types.in.h b/lib/sys_types.in.h index ed9e9506a1..acf9b2f754 100644 --- a/lib/sys_types.in.h +++ b/lib/sys_types.in.h @@ -117,6 +117,22 @@ typedef unsigned long long int rpl_ino_t; # include #endif +/* Define blksize_t, required by POSIX:2024. */ +#if !@HAVE_BLKSIZE_T@ +# if !defined GNULIB_defined_blksize_t +typedef int blksize_t; +# define GNULIB_defined_blksize_t 1 +# endif +#endif + +/* Define blkcnt_t, required by POSIX:2024. */ +#if !@HAVE_BLKCNT_T@ +# if !defined GNULIB_defined_blkcnt_t +typedef long long blkcnt_t; +# define GNULIB_defined_blkcnt_t 1 +# endif +#endif + #endif /* _@GUARD_PREFIX@_SYS_TYPES_H */ #endif /* _@GUARD_PREFIX@_SYS_TYPES_H */ #endif /* __need_XXX */ diff --git a/m4/sys_types_h.m4 b/m4/sys_types_h.m4 index e13de24a78..e99fdcc6c2 100644 --- a/m4/sys_types_h.m4 +++ b/m4/sys_types_h.m4 @@ -1,5 +1,5 @@ # sys_types_h.m4 -# serial 14 +# serial 15 dnl Copyright (C) 2011-2025 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -34,6 +34,14 @@ AC_DEFUN_ONCE([gl_SYS_TYPES_H], WINDOWS_STAT_INODES=0 ]) AC_SUBST([WINDOWS_STAT_INODES]) + + dnl Test whether the 'blksize_t' type is defined. + AC_CHECK_TYPE([blksize_t], [HAVE_BLKSIZE_T=1], [HAVE_BLKSIZE_T=0]) + AC_SUBST([HAVE_BLKSIZE_T]) + + dnl Test whether the 'blkcnt_t' type is defined. + AC_CHECK_TYPE([blkcnt_t], [HAVE_BLKCNT_T=1], [HAVE_BLKCNT_T=0]) + AC_SUBST([HAVE_BLKCNT_T]) ]) # Initializes the default values for AC_SUBSTed shell variables. diff --git a/modules/sys_types-h b/modules/sys_types-h index b878a03e1b..cd3b261894 100644 --- a/modules/sys_types-h +++ b/modules/sys_types-h @@ -37,6 +37,8 @@ sys/types.h: sys_types.in.h $(top_builddir)/config.status -e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \ -e 's|@''HAVE_OFF64_T''@|$(HAVE_OFF64_T)|g' \ -e 's|@''WINDOWS_STAT_INODES''@|$(WINDOWS_STAT_INODES)|g' \ + -e 's|@''HAVE_BLKSIZE_T''@|$(HAVE_BLKSIZE_T)|g' \ + -e 's|@''HAVE_BLKCNT_T''@|$(HAVE_BLKCNT_T)|g' \ $(srcdir)/sys_types.in.h > $@-t $(AM_V_at)mv $@-t $@ MOSTLYCLEANFILES += sys/types.h sys/types.h-t diff --git a/modules/sys_types-h-tests b/modules/sys_types-h-tests index 4b42da3bb4..619f321f76 100644 --- a/modules/sys_types-h-tests +++ b/modules/sys_types-h-tests @@ -2,6 +2,8 @@ Files: tests/test-sys_types-h.c Depends-on: +assert-h +intprops sys_types-h-c++-tests configure.ac: diff --git a/tests/test-sys_types-h.c b/tests/test-sys_types-h.c index 6bfaec1966..ab54d5d3bb 100644 --- a/tests/test-sys_types-h.c +++ b/tests/test-sys_types-h.c @@ -20,13 +20,40 @@ #include -/* Check that the types are all defined. */ +/* Check that the most important types are defined. */ pid_t t1; size_t t2; ssize_t t3; off_t t4; mode_t t5; off64_t t6; +blksize_t t7; +blkcnt_t t8; + +#include "intprops.h" + +/* POSIX requires that pid_t is a signed integer type. */ +static_assert (TYPE_SIGNED (pid_t)); + +/* POSIX requires that size_t is an unsigned integer type. */ +static_assert (! TYPE_SIGNED (size_t)); + +/* POSIX requires that ssize_t is a signed integer type. */ +static_assert (TYPE_SIGNED (ssize_t)); + +/* POSIX requires that off_t is a signed integer type. */ +static_assert (TYPE_SIGNED (off_t)); +static_assert (TYPE_SIGNED (off64_t)); + +/* POSIX requires that blksize_t is a signed integer type. */ +#if !defined __ANDROID__ +static_assert (TYPE_SIGNED (blksize_t)); +#endif + +/* POSIX requires that blkcnt_t is a signed integer type. */ +#if !defined __ANDROID__ +static_assert (TYPE_SIGNED (blkcnt_t)); +#endif int main (void) -- 2.39.5