From adc372decc54eea2da8f2a7f5587be939aa8b6e3 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 27 Apr 2024 19:46:34 +0200 Subject: [PATCH] sys_types: Ensure off64_t is defined on all platforms. * m4/off64_t.m4: New file. * m4/sys_types_h.m4 (gl_SYS_TYPES_H): Require gl_TYPE_OFF64_T. * lib/sys_types.in.h (off64_t): New type. (GNULIB_defined_off64_t): New macro. * modules/sys_types (Files): Add m4/off64_t.m4. (configure.ac-early): Require AC_USE_SYSTEM_EXTENSIONS. (Makefile.am): Substitute HAVE_OFF64_T. * tests/test-sys_types.c: Verify that off64_t is defined. * doc/posix-headers/sys_types.texi: Mention the off64_t workaround. --- ChangeLog | 13 +++++++++++++ doc/posix-headers/sys_types.texi | 3 +++ lib/sys_types.in.h | 9 +++++++++ m4/off64_t.m4 | 31 +++++++++++++++++++++++++++++++ m4/sys_types_h.m4 | 5 ++++- modules/sys_types | 5 +++++ tests/test-sys_types.c | 1 + 7 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 m4/off64_t.m4 diff --git a/ChangeLog b/ChangeLog index e341b62968..8467f57a50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2024-04-27 Bruno Haible + + sys_types: Ensure off64_t is defined on all platforms. + * m4/off64_t.m4: New file. + * m4/sys_types_h.m4 (gl_SYS_TYPES_H): Require gl_TYPE_OFF64_T. + * lib/sys_types.in.h (off64_t): New type. + (GNULIB_defined_off64_t): New macro. + * modules/sys_types (Files): Add m4/off64_t.m4. + (configure.ac-early): Require AC_USE_SYSTEM_EXTENSIONS. + (Makefile.am): Substitute HAVE_OFF64_T. + * tests/test-sys_types.c: Verify that off64_t is defined. + * doc/posix-headers/sys_types.texi: Mention the off64_t workaround. + 2024-04-27 Paul Eggert nullptr: work around GCC 14 nullptr sentinel bug diff --git a/doc/posix-headers/sys_types.texi b/doc/posix-headers/sys_types.texi index 8739cc2625..f30d8b9d79 100644 --- a/doc/posix-headers/sys_types.texi +++ b/doc/posix-headers/sys_types.texi @@ -20,6 +20,9 @@ MSVC 14. The type @code{mode_t} is not defined on some platforms: MSVC 14. @item +The type @code{off64_t} is not defined on some platforms: +macOS 12.5, FreeBSD 10.4, NetBSD 10.0, OpenBSD 7.5, MSVC 14, Cygwin, Haiku, Minix 3.3. +@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 diff --git a/lib/sys_types.in.h b/lib/sys_types.in.h index 0a0ccc3c37..4eb2e92696 100644 --- a/lib/sys_types.in.h +++ b/lib/sys_types.in.h @@ -60,6 +60,15 @@ # define _GL_WINDOWS_64_BIT_OFF_T 1 #endif +/* Define the off64_t type. */ +#if !@HAVE_OFF64_T@ +# if !GNULIB_defined_off64_t +/* Define off64_t to int64_t always. */ +typedef long long off64_t; +# define GNULIB_defined_off64_t 1 +# endif +#endif + /* Override dev_t and ino_t if distinguishable inodes support is requested on native Windows. */ #if @WINDOWS_STAT_INODES@ diff --git a/m4/off64_t.m4 b/m4/off64_t.m4 new file mode 100644 index 0000000000..34fa21eb16 --- /dev/null +++ b/m4/off64_t.m4 @@ -0,0 +1,31 @@ +# off64_t.m4 +# serial 1 +dnl Copyright (C) 2024 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Check whether defines the 'off64_t' type. +dnl Set HAVE_OFF64_T. + +AC_DEFUN([gl_TYPE_OFF64_T], +[ + dnl Persuade glibc , , , , + dnl to define off64_t. + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_CACHE_CHECK([for off64_t], [gl_cv_off64_t], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[int x = sizeof (off64_t *) + sizeof (off64_t); + return !x;]])], + [gl_cv_off64_t=yes], [gl_cv_off64_t=no])]) + + if test $gl_cv_off64_t != no; then + HAVE_OFF64_T=1 + else + HAVE_OFF64_T=0 + fi + AC_SUBST([HAVE_OFF64_T]) +]) diff --git a/m4/sys_types_h.m4 b/m4/sys_types_h.m4 index 00d2437b03..7c7f265527 100644 --- a/m4/sys_types_h.m4 +++ b/m4/sys_types_h.m4 @@ -1,5 +1,5 @@ # sys_types_h.m4 -# serial 13 +# serial 14 dnl Copyright (C) 2011-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -23,6 +23,9 @@ AC_DEFUN_ONCE([gl_SYS_TYPES_H], dnl Whether to override the 'off_t' type. AC_REQUIRE([gl_TYPE_OFF_T]) + dnl Whether to define the 'off64_t' type. + AC_REQUIRE([gl_TYPE_OFF64_T]) + dnl Whether to override the 'dev_t' and 'ino_t' types. m4_ifdef([gl_WINDOWS_STAT_INODES], [ AC_REQUIRE([gl_WINDOWS_STAT_INODES]) diff --git a/modules/sys_types b/modules/sys_types index 96849aa3b1..3518b17dbe 100644 --- a/modules/sys_types +++ b/modules/sys_types @@ -5,6 +5,7 @@ Files: lib/sys_types.in.h m4/sys_types_h.m4 m4/off_t.m4 +m4/off64_t.m4 m4/pid_t.m4 Depends-on: @@ -12,6 +13,9 @@ gen-header include_next ssize_t +configure.ac-early: +AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + configure.ac: gl_SYS_TYPES_H gl_SYS_TYPES_H_REQUIRE_DEFAULTS @@ -31,6 +35,7 @@ sys/types.h: sys_types.in.h $(top_builddir)/config.status -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_SYS_TYPES_H''@|$(NEXT_SYS_TYPES_H)|g' \ -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' \ $(srcdir)/sys_types.in.h > $@-t $(AM_V_at)mv $@-t $@ diff --git a/tests/test-sys_types.c b/tests/test-sys_types.c index f661a92153..46da846ef2 100644 --- a/tests/test-sys_types.c +++ b/tests/test-sys_types.c @@ -26,6 +26,7 @@ size_t t2; ssize_t t3; off_t t4; mode_t t5; +off64_t t6; int main (void) -- 2.39.5