Building a recent coreutils snapshot on FreeBSD 5.2.1, I see this compilation
error:

  CC       src/tail.o
../src/tail.c: In function `file_lines':
../src/tail.c:524: error: syntax error before "bufsize"
../src/tail.c:542: error: `bufsize' undeclared (first use in this function)
../src/tail.c:542: error: (Each undeclared identifier is reported only once
../src/tail.c:542: error: for each function it appears in.)
gmake[2]: *** [src/tail.o] Error 1

The cause is that coreutils now uses the 'blksize_t' type; however,
older versions of FreeBSD and OpenBSD lack this type.

These two patches guarantee that gnulib's 'sys_types-h' and 'sys_stat-h'
modules define 'blksize_t' if the system does not have it.
And, while we're at it, also 'blkcnt_t'.


2025-01-17  Bruno Haible  <br...@clisp.org>

        sys_stat-h: Ensure blksize_t and blkcnt_t are defined.
        * tests/test-sys_stat-h.c: Check that blksize_t and blkcnt_t are
        defined. Include intprops.h. Check the signedness of various types.
        * modules/sys_stat-h-tests (Depends-on): Add intprops.
        * doc/posix-headers/sys_stat.texi: Mention the issues with blksize_t and
        blkcnt_t.

        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.

>From 4af8d6a0e574ea39b65517cfcb198d7d81e03d65 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 17 Jan 2025 22:32:58 +0100
Subject: [PATCH 1/2] 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  <br...@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  <egg...@cs.ucla.edu>
 
 	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 @@
 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 @@
 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 <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 */
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 <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)
-- 
2.43.0

>From b4ead0073268f32338e7ee348c87a75f0d8d1dba Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 17 Jan 2025 22:51:55 +0100
Subject: [PATCH 2/2] sys_stat-h: Ensure blksize_t and blkcnt_t are defined.

* tests/test-sys_stat-h.c: Check that blksize_t and blkcnt_t are
defined. Include intprops.h. Check the signedness of various types.
* modules/sys_stat-h-tests (Depends-on): Add intprops.
* doc/posix-headers/sys_stat.texi: Mention the issues with blksize_t and
blkcnt_t.
---
 ChangeLog                       |  7 +++++++
 doc/posix-headers/sys_stat.texi |  9 +++++++++
 modules/sys_stat-h-tests        |  1 +
 tests/test-sys_stat-h.c         | 17 +++++++++++++++++
 4 files changed, 34 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 8b77cac9ee..f41d5c885f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2025-01-17  Bruno Haible  <br...@clisp.org>
 
+	sys_stat-h: Ensure blksize_t and blkcnt_t are defined.
+	* tests/test-sys_stat-h.c: Check that blksize_t and blkcnt_t are
+	defined. Include intprops.h. Check the signedness of various types.
+	* modules/sys_stat-h-tests (Depends-on): Add intprops.
+	* doc/posix-headers/sys_stat.texi: Mention the issues with blksize_t and
+	blkcnt_t.
+
 	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
diff --git a/doc/posix-headers/sys_stat.texi b/doc/posix-headers/sys_stat.texi
index bc889e986f..764451255f 100644
--- a/doc/posix-headers/sys_stat.texi
+++ b/doc/posix-headers/sys_stat.texi
@@ -12,6 +12,12 @@
 The type @code{mode_t} is not defined on some platforms:
 MSVC 14.
 @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 macros, such as @code{S_IFMT} or @code{S_IFIFO}, are missing on some
 platforms.
 @item
@@ -54,6 +60,9 @@
 Portability problems not fixed by Gnulib:
 @itemize
 @item
+On some platforms the types @code{blksize_t} and @code{blkcnt_t} are unsigned:
+Android.
+@item
 The macro @code{S_IFBLK} is missing on some platforms:
 MSVC 14.
 @item
diff --git a/modules/sys_stat-h-tests b/modules/sys_stat-h-tests
index a13ea11e45..aa853c5bad 100644
--- a/modules/sys_stat-h-tests
+++ b/modules/sys_stat-h-tests
@@ -3,6 +3,7 @@ tests/test-sys_stat-h.c
 
 Depends-on:
 assert-h
+intprops
 sys_stat-h-c++-tests
 
 configure.ac:
diff --git a/tests/test-sys_stat-h.c b/tests/test-sys_stat-h.c
index f433935fb1..510aa21ea3 100644
--- a/tests/test-sys_stat-h.c
+++ b/tests/test-sys_stat-h.c
@@ -328,9 +328,26 @@ invalid UTIME macros
 nlink_t t1;
 off_t t2;
 mode_t t3;
+blksize_t t4;
+blkcnt_t t5;
 
 struct timespec st;
 
+#include "intprops.h"
+
+/* POSIX requires that off_t is a signed integer type.  */
+static_assert (TYPE_SIGNED (off_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.43.0

Reply via email to