]> Savannah Git Hosting - gnulib.git/commitdiff
sys_types-h: Ensure blksize_t and blkcnt_t are defined.
authorBruno Haible <bruno@clisp.org>
Fri, 17 Jan 2025 21:32:58 +0000 (22:32 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 17 Jan 2025 21:32:58 +0000 (22:32 +0100)
* 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
doc/posix-headers/sys_types.texi
lib/sys_types.in.h
m4/sys_types_h.m4
modules/sys_types-h
modules/sys_types-h-tests
tests/test-sys_types-h.c

index 5796c80ae06c61b507fd04112e9d003a4da587da..8b77cac9ee9a0a5c2daf6ef901189a1fff1f4a22 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2025-01-17  Bruno Haible  <bruno@clisp.org>
+
+       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  <eggert@cs.ucla.edu>
 
        crc-x86_64: port to old GCC compilers
index 2684e23a58c933b2eb149ef2981dc6186cba4450..ed301c4b2c4c488dfb9789fd266ceafa7758c1c9 100644 (file)
@@ -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
index ed9e9506a10fcf15baa1c08df8cb122757c0ffd3..acf9b2f754673be124202b7962d7fb6b36c56fb6 100644 (file)
@@ -117,6 +117,22 @@ typedef unsigned long long int rpl_ino_t;
 # include <stddef.h>
 #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 */
index e13de24a7847fdac06d131241a79034f723f7983..e99fdcc6c2f309d3aadb26fd7873858c3408859d 100644 (file)
@@ -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.
index b878a03e1b04c4833192c45447bb7aa7e7d723de..cd3b26189451310e7331c81512c83e0472ccb637 100644 (file)
@@ -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
index 4b42da3bb4446f1c1a0e23eedba3954eb31190b0..619f321f76bae21b2ec4484b9ae0468d5e1a45ee 100644 (file)
@@ -2,6 +2,8 @@ Files:
 tests/test-sys_types-h.c
 
 Depends-on:
+assert-h
+intprops
 sys_types-h-c++-tests
 
 configure.ac:
index 6bfaec196683b813314a30665b7da074d56ef4e7..ab54d5d3bbf6d4c1acc9f29b8a6a8d08842dc485 100644 (file)
 
 #include <sys/types.h>
 
-/* 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)