Paul Eggert wrote: > now that you mention off64_t it strikes me that zoff_t would > basically be off64_t, and off64_t has had its own problems: its only use > in apps is to deal with deficient libraries, and it is a pain in > libraries (where its only use is to deal with deficient apps :-). I > don't offhand see why zoff_t would do any better than off64_t has done, > or why we would need to give a new name to this unloved type.
You've convinced me to use off64_t instead of zoff_t. My main argument against off64_t was that it is non-standard. But - There is no platform where off64_t is different from int64_t. - off64_t is defined by glibc, and since Gnulib's job is to offer the APIs provided by glibc portably, as far as possible, below are two patches that implement off64_t portably. With that done, there is indeed no reason any more to invent zoff_t. Some notes: - In glibc, off64_t is defined in <sys/types.h>, <fcntl.h>, <stdio.h>, <unistd.h>, <aio.h>. - In POSIX, off_t is defined in the same header files, and also in <sys/stat.h> and <sys/mman.h>. - off64_t is existent and equivalent to 'long long' on glibc, musl, FreeBSD, AIX, HP-UX, IRIX, Solaris, mingw, Android. - off64_t is missing on macOS, FreeBSD ≤ 10, NetBSD, OpenBSD, MSVC, Cygwin, Haiku, Minix. - The configure.ac-early section is because otherwise I got an autoconf warning configure.ac:211: warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS glm4/off64_t.m4:11: gl_TYPE_OFF64_T is expanded from... configure.ac:28: gl_INIT is expanded from... configure.ac:211: the top level configure.ac:211: warning: AC_CHECK_INCLUDES_DEFAULT was called before AC_USE_SYSTEM_EXTENSIONS glm4/off64_t.m4:11: gl_TYPE_OFF64_T is expanded from... configure.ac:28: gl_INIT is expanded from... configure.ac:211: the top level I don't know why this has not already occurred earlier; we have dozens of modules which require AC_USE_SYSTEM_EXTENSIONS. 2024-04-27 Bruno Haible <br...@clisp.org> fcntl-h, stdio, unistd: Ensure off64_t is defined on all platforms. * lib/fcntl.in.h: Update comment regarding off64_t. * lib/stdio.in.h: Likewise. * lib/unistd.in.h: Likewise. * tests/test-fcntl-h.c: Verify that off64_t is defined. * tests/test-stdio.c: Likewise. * tests/test-unistd.c: Likewise. * doc/posix-headers/fcntl.texi: Mention the off64_t workaround. * doc/posix-headers/stdio.texi: Likewise. * doc/posix-headers/unistd.texi: Likewise. * doc/posix-headers/aio.texi: Mention the problem with off64_t. 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.
>From adc372decc54eea2da8f2a7f5587be939aa8b6e3 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 27 Apr 2024 19:46:34 +0200 Subject: [PATCH 1/2] 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 <br...@clisp.org> + + 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 <egg...@cs.ucla.edu> 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 @@ 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 <sys/types.h> defines the 'off64_t' type. +dnl Set HAVE_OFF64_T. + +AC_DEFUN([gl_TYPE_OFF64_T], +[ + dnl Persuade glibc <sys/types.h>, <stdio.h>, <fcntl.h>, <unistd.h>, <aio.h> + 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 <sys/types.h>]], + [[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.34.1
>From 13496d1e83af41fa67b5352ad8a08fee1da7fff2 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 27 Apr 2024 19:51:53 +0200 Subject: [PATCH 2/2] fcntl-h, stdio, unistd: Ensure off64_t is defined on all platforms. * lib/fcntl.in.h: Update comment regarding off64_t. * lib/stdio.in.h: Likewise. * lib/unistd.in.h: Likewise. * tests/test-fcntl-h.c: Verify that off64_t is defined. * tests/test-stdio.c: Likewise. * tests/test-unistd.c: Likewise. * doc/posix-headers/fcntl.texi: Mention the off64_t workaround. * doc/posix-headers/stdio.texi: Likewise. * doc/posix-headers/unistd.texi: Likewise. * doc/posix-headers/aio.texi: Mention the problem with off64_t. --- ChangeLog | 12 ++++++++++++ doc/posix-headers/aio.texi | 5 ++++- doc/posix-headers/fcntl.texi | 4 ++++ doc/posix-headers/stdio.texi | 9 ++++++--- doc/posix-headers/unistd.texi | 3 +++ lib/fcntl.in.h | 3 ++- lib/stdio.in.h | 3 ++- lib/unistd.in.h | 5 +++-- tests/test-fcntl-h.c | 1 + tests/test-stdio.c | 1 + tests/test-unistd.c | 1 + 11 files changed, 39 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8467f57a50..935ddbd1ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2024-04-27 Bruno Haible <br...@clisp.org> + fcntl-h, stdio, unistd: Ensure off64_t is defined on all platforms. + * lib/fcntl.in.h: Update comment regarding off64_t. + * lib/stdio.in.h: Likewise. + * lib/unistd.in.h: Likewise. + * tests/test-fcntl-h.c: Verify that off64_t is defined. + * tests/test-stdio.c: Likewise. + * tests/test-unistd.c: Likewise. + * doc/posix-headers/fcntl.texi: Mention the off64_t workaround. + * doc/posix-headers/stdio.texi: Likewise. + * doc/posix-headers/unistd.texi: Likewise. + * doc/posix-headers/aio.texi: Mention the problem with off64_t. + 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. diff --git a/doc/posix-headers/aio.texi b/doc/posix-headers/aio.texi index b8c958756b..69b865b2ec 100644 --- a/doc/posix-headers/aio.texi +++ b/doc/posix-headers/aio.texi @@ -13,5 +13,8 @@ @itemize @item This header file is missing on some platforms: -NetBSD 3.0, OpenBSD 6.7, Minix 3.1.8, Cygwin, mingw, MSVC 14, Android 9.0. +NetBSD 3.0, OpenBSD 6.7, Minix 3.1.8, Cygwin, mingw, MSVC 14, Haiku, Android 9.0. +@item +The type @code{off64_t} is not defined on some platforms: +macOS 12.5, FreeBSD 10.4, NetBSD 10.0, OpenBSD 7.5, Minix 3.3. @end itemize diff --git a/doc/posix-headers/fcntl.texi b/doc/posix-headers/fcntl.texi index 0982ba9aa5..d7d95ba1ca 100644 --- a/doc/posix-headers/fcntl.texi +++ b/doc/posix-headers/fcntl.texi @@ -15,6 +15,10 @@ 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 @samp{O_CLOEXEC} is not defined on some platforms: Mac OS X 10.6, FreeBSD 8.4, NetBSD 5.1, OpenBSD 4.9, Minix 3.1.8, AIX 7.1, HP-UX 11.31, Solaris 10, Cygwin 1.7.1, mingw, MSVC 14. diff --git a/doc/posix-headers/stdio.texi b/doc/posix-headers/stdio.texi index cb5a76f55d..9dc2e68b58 100644 --- a/doc/posix-headers/stdio.texi +++ b/doc/posix-headers/stdio.texi @@ -8,15 +8,18 @@ Portability problems fixed by Gnulib: @itemize @item -The type @code{off_t} is missing on some platforms: +The type @code{off_t} is not defined on some platforms: glibc 2.8, eglibc 2.11.2 and others. @item -The type @code{ssize_t} is missing on some platforms: +The type @code{ssize_t} is not defined on some platforms: glibc 2.8, Mac OS X 10.5, Solaris 10, MSVC 14, and others. @item -The type @code{va_list} is missing on some platforms: +The type @code{va_list} is not defined on some platforms: glibc 2.8, OpenBSD 4.0, Solaris 11.4, and others. @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 platforms provide a @code{NULL} macro that cannot be used in arbitrary expressions: NetBSD 5.0 diff --git a/doc/posix-headers/unistd.texi b/doc/posix-headers/unistd.texi index 2327e6ff4a..1f5312f8d0 100644 --- a/doc/posix-headers/unistd.texi +++ b/doc/posix-headers/unistd.texi @@ -11,6 +11,9 @@ This header file is missing 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 The SEEK_* macros are not defined in this file on some platforms: mingw. @item diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h index eea3b9542a..1465ce594d 100644 --- a/lib/fcntl.in.h +++ b/lib/fcntl.in.h @@ -51,7 +51,8 @@ #ifndef _@GUARD_PREFIX@_FCNTL_H /* Needed before <sys/stat.h>. - May also define off_t to a 64-bit type on native Windows. */ + May also define off_t to a 64-bit type on native Windows. + Also defines off64_t on macOS, NetBSD, OpenBSD, MSVC, Cygwin, Haiku. */ #include <sys/types.h> /* On some systems other than glibc, <sys/stat.h> is a prerequisite of <fcntl.h>. On glibc systems, we would like to avoid namespace pollution. diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 35b9f74821..1c0c9661bf 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -77,7 +77,8 @@ /* Get off_t and ssize_t. Needed on many systems, including glibc 2.8 and eglibc 2.11.2. - May also define off_t to a 64-bit type on native Windows. */ + May also define off_t to a 64-bit type on native Windows. + Also defines off64_t on macOS, NetBSD, OpenBSD, MSVC, Cygwin, Haiku. */ #include <sys/types.h> /* Solaris 10 and NetBSD 7.0 declare renameat in <unistd.h>, not in <stdio.h>. */ diff --git a/lib/unistd.in.h b/lib/unistd.in.h index b412966367..fa99d7472f 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -159,8 +159,9 @@ #endif /* MSVC defines off_t in <sys/types.h>. - May also define off_t to a 64-bit type on native Windows. */ -/* Get off_t, ssize_t, mode_t. */ + May also define off_t to a 64-bit type on native Windows. + Also defines off64_t on macOS, NetBSD, OpenBSD, MSVC, Cygwin, Haiku. */ +/* Get off_t, off64_t, ssize_t, mode_t. */ #include <sys/types.h> /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ diff --git a/tests/test-fcntl-h.c b/tests/test-fcntl-h.c index d633167235..6020a11e72 100644 --- a/tests/test-fcntl-h.c +++ b/tests/test-fcntl-h.c @@ -35,6 +35,7 @@ int i = FD_CLOEXEC; pid_t t1; off_t t2; mode_t t3; +off64_t t4; int main (void) diff --git a/tests/test-stdio.c b/tests/test-stdio.c index 499695206b..44d58f0556 100644 --- a/tests/test-stdio.c +++ b/tests/test-stdio.c @@ -36,6 +36,7 @@ off_t t2; size_t t3; ssize_t t4; va_list t5; +off64_t t6; #include <string.h> diff --git a/tests/test-unistd.c b/tests/test-unistd.c index 931d65e439..e131302ab6 100644 --- a/tests/test-unistd.c +++ b/tests/test-unistd.c @@ -46,6 +46,7 @@ pid_t t6; useconds_t t7; intptr_t t8; #endif +off64_t t9; int main (void) -- 2.34.1