A bit ago, I noticed that Haiku failed to build to to privatizing of
libio.h [1].  Much of this was fixed since Haiku added since they added
stdio_ext.h.

However, there was still some breakage for fseeko:

    $ cat ../output.txt 
    fseeko.c: In function 'rpl_fseeko':
    fseeko.c:111:4: error: #error "Please port gnulib fseeko.c to your 
platform! Look at the code in fseeko.c, then report this to bug-gnulib."
      111 |   #error "Please port gnulib fseeko.c to your platform! Look at the 
code in fseeko.c, then report this to bug-gnulib."
          |    ^~~~~
    Makefile:12117: recipe for target 'fseeko.o' failed
    make[4]: *** [fseeko.o] Error 1

Finally, I have decided to stop being lazy and fixed it with the first
attached patch.

I ran into similar issues for fbufmode, a Gnulib function, and fflush
which requires fixes on Haiku. Fixed with the second and third attached
patch.

Lastly, although Haiku added __fseterr recently, it is missing a
declaration. The fourth patch fixes that, and I have updated my original
bug report there [2].

Jim, Pádraig, I am fairly certain that your packages will include these
modules as a transitive dependency if they do not include them
directly. To confirm, I could build the latest Diffutils and Grep
snapshots. However, the latest Coreutils and Gzip snapshots fail. I'm
sure the Haiku people will appreciate not having to patch these files if
you can update them before you release. :)

Collin

[1] https://lists.gnu.org/archive/html/bug-gnulib/2025-03/msg00051.html
[2] https://dev.haiku-os.org/ticket/19479

>From 58195177985347cff52d402622d264daa2f8e179 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 6 Apr 2025 19:19:35 -0700
Subject: [PATCH 1/4] fseeko: Port to recent Haiku snapshots.

* lib/stdio-impl.h (fp_) [__HAIKU__]: Define to FILE which is an
incomplete type on Haiku.
(_IO_EOF_SEEN) [__HAIKU__]: Define macro.
* lib/fseeko.c (fp_) [!__HAIKU__]: Define to fp.
(fseeko): Use fp_ instead of fp.
---
 ChangeLog        |  9 +++++++++
 lib/fseeko.c     | 13 ++++++++-----
 lib/stdio-impl.h | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 53db9e00a0..d2fe415247 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-04-06  Collin Funk  <collin.fu...@gmail.com>
+
+	fseeko: Port to recent Haiku snapshots.
+	* lib/stdio-impl.h (fp_) [__HAIKU__]: Define to FILE which is an
+	incomplete type on Haiku.
+	(_IO_EOF_SEEN) [__HAIKU__]: Define macro.
+	* lib/fseeko.c (fp_) [!__HAIKU__]: Define to fp.
+	(fseeko): Use fp_ instead of fp.
+
 2025-04-04  Eric Blake  <ebl...@redhat.com>
 
 	tests: Better name in init.sh usage.
diff --git a/lib/fseeko.c b/lib/fseeko.c
index c15b9e210f..b39099c4a0 100644
--- a/lib/fseeko.c
+++ b/lib/fseeko.c
@@ -48,10 +48,13 @@ fseeko (FILE *fp, off_t offset, int whence)
 
   /* These tests are based on fpurge.c.  */
 #if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
+# if !defined __HAIKU__
+#  define fp_ fp
+# endif
   /* GNU libc, BeOS, Haiku, Linux libc5 */
-  if (fp->_IO_read_end == fp->_IO_read_ptr
-      && fp->_IO_write_ptr == fp->_IO_write_base
-      && fp->_IO_save_base == NULL)
+  if (fp_->_IO_read_end == fp_->_IO_read_ptr
+      && fp_->_IO_write_ptr == fp_->_IO_write_base
+      && fp_->_IO_save_base == NULL)
 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
   /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
 # if defined __SL64 && defined __SCLE /* Cygwin */
@@ -126,8 +129,8 @@ fseeko (FILE *fp, off_t offset, int whence)
 
 #if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
       /* GNU libc, BeOS, Haiku, Linux libc5 */
-      fp->_flags &= ~_IO_EOF_SEEN;
-      fp->_offset = pos;
+      fp_->_flags &= ~_IO_EOF_SEEN;
+      fp_->_offset = pos;
 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
       /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
 # if defined __CYGWIN__ || (defined __NetBSD__ && __NetBSD_Version__ >= 600000000) || defined __minix
diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h
index 878e9f8c97..b6be050676 100644
--- a/lib/stdio-impl.h
+++ b/lib/stdio-impl.h
@@ -30,6 +30,40 @@
 # endif
 #endif
 
+/* Haiku stdio implementation.  */
+#if defined __HAIKU__
+# include <stdint.h>
+/* This FILE structure was made into an incomplete type in 2025.
+   See <https://cgit.haiku-os.org/haiku/tree/src/system/libroot/posix/glibc/libio/libio.h>.  */
+#  define fp_ ((struct { int _flags; \
+                         char *_IO_read_ptr; \
+                         char *_IO_read_end; \
+                         char *_IO_read_base; \
+                         char *_IO_write_base; \
+                         char *_IO_write_ptr; \
+                         char *_IO_write_end; \
+                         char *_IO_buf_base; \
+                         char *_IO_buf_end; \
+                         char *_IO_save_base; \
+                         char *_IO_backup_base; \
+                         char *_IO_save_end; \
+                         void *_markers; \
+                         void *_chain; \
+                         int _fileno; \
+                         int _flags2; \
+                         off_t _old_offset; \
+                         unsigned short _cur_column; \
+                         signed char _vtable_offset; \
+                         char _shortbuf[1]; \
+                         void *_lock; \
+                         int64_t _offset; \
+                         /* More fields, not relevant here.  */ \
+                       } *) fp)
+# if !defined _IO_EOF_SEEN
+#  define _IO_EOF_SEEN 0x10
+# endif
+#endif
+
 /* BSD stdio derived implementations.  */
 
 #if defined __NetBSD__                         /* NetBSD */
-- 
2.49.0

>From a4bcf257083ce6fc7ccc827e5db1b5aa594dd9e3 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 6 Apr 2025 19:28:27 -0700
Subject: [PATCH 2/4] fbufmode: Port to recent Haiku snapshots.

* lib/stdio-impl.h (_IO_UNBUFFERED, _IO_LINE_BUF) [__HAIKU__]: Define
macros.
* lib/fbufmode.c (fp_) [!__HAIKU__]: Define to fp.
(fbufmode): Use fp_ instead of fp.
---
 ChangeLog        | 6 ++++++
 lib/fbufmode.c   | 7 +++++--
 lib/stdio-impl.h | 6 ++++++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d2fe415247..289624f453 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2025-04-06  Collin Funk  <collin.fu...@gmail.com>
 
+	fbufmode: Port to recent Haiku snapshots.
+	* lib/stdio-impl.h (_IO_UNBUFFERED, _IO_LINE_BUF) [__HAIKU__]: Define
+	macros.
+	* lib/fbufmode.c (fp_) [!__HAIKU__]: Define to fp.
+	(fbufmode): Use fp_ instead of fp.
+
 	fseeko: Port to recent Haiku snapshots.
 	* lib/stdio-impl.h (fp_) [__HAIKU__]: Define to FILE which is an
 	incomplete type on Haiku.
diff --git a/lib/fbufmode.c b/lib/fbufmode.c
index 57aac73292..db0e6b456b 100644
--- a/lib/fbufmode.c
+++ b/lib/fbufmode.c
@@ -34,15 +34,18 @@ fbufmode (FILE *fp)
      <stdio.h>, because they need it for implementing getc() and putc() as
      fast macros.  */
 #if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
+# if !defined __HAIKU__
+#  define fp_ fp
+# endif
   /* GNU libc, BeOS, Haiku, Linux libc5 */
 # if HAVE___FLBF                    /* glibc >= 2.2 */
   if (__flbf (fp))
     return _IOLBF;
 # else
-  if (fp->_flags & _IO_LINE_BUF)
+  if (fp_->_flags & _IO_LINE_BUF)
     return _IOLBF;
 # endif
-  if (fp->_flags & _IO_UNBUFFERED)
+  if (fp_->_flags & _IO_UNBUFFERED)
     return _IONBF;
   return _IOFBF;
 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h
index b6be050676..2e7bf1a7c7 100644
--- a/lib/stdio-impl.h
+++ b/lib/stdio-impl.h
@@ -59,9 +59,15 @@
                          int64_t _offset; \
                          /* More fields, not relevant here.  */ \
                        } *) fp)
+# if !defined _IO_UNBUFFERED
+#  define _IO_UNBUFFERED 0x2
+# endif
 # if !defined _IO_EOF_SEEN
 #  define _IO_EOF_SEEN 0x10
 # endif
+# if !defined _IO_LINE_BUF
+#  define _IO_LINE_BUF 0x200
+# endif
 #endif
 
 /* BSD stdio derived implementations.  */
-- 
2.49.0

>From ebbd322ff029a9212274df18f1aeac27cc6df6b6 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 6 Apr 2025 19:34:54 -0700
Subject: [PATCH 3/4] fflush: Port to recent Haiku snapshots.

* lib/stdio-impl.h (_IO_IN_BACKUP) [__HAIKU__]: Define macros.
* lib/fflush.c (fp_) [!__HAIKU__]: Define to fp.
(fflush): Use fp_ instead of fp.
---
 ChangeLog        | 5 +++++
 lib/fflush.c     | 5 ++++-
 lib/stdio-impl.h | 3 +++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 289624f453..d1a16e15da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2025-04-06  Collin Funk  <collin.fu...@gmail.com>
 
+	fflush: Port to recent Haiku snapshots.
+	* lib/stdio-impl.h (_IO_IN_BACKUP) [__HAIKU__]: Define macros.
+	* lib/fflush.c (fp_) [!__HAIKU__]: Define to fp.
+	(fflush): Use fp_ instead of fp.
+
 	fbufmode: Port to recent Haiku snapshots.
 	* lib/stdio-impl.h (_IO_UNBUFFERED, _IO_LINE_BUF) [__HAIKU__]: Define
 	macros.
diff --git a/lib/fflush.c b/lib/fflush.c
index 85af768ce7..9e256f3272 100644
--- a/lib/fflush.c
+++ b/lib/fflush.c
@@ -33,12 +33,15 @@
 
 #if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
 /* GNU libc, BeOS, Haiku, Linux libc5 */
+# if !defined __HAIKU__
+#  define fp_ fp
+# endif
 
 /* Clear the stream's ungetc buffer, preserving the value of ftello (fp).  */
 static void
 clear_ungetc_buffer_preserving_position (FILE *fp)
 {
-  if (fp->_flags & _IO_IN_BACKUP)
+  if (fp_->_flags & _IO_IN_BACKUP)
     /* _IO_free_backup_area is a bit complicated.  Simply call fseek.  */
     fseeko (fp, 0, SEEK_CUR);
 }
diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h
index 2e7bf1a7c7..4b4263fe90 100644
--- a/lib/stdio-impl.h
+++ b/lib/stdio-impl.h
@@ -65,6 +65,9 @@
 # if !defined _IO_EOF_SEEN
 #  define _IO_EOF_SEEN 0x10
 # endif
+# if !defined _IO_IN_BACKUP
+#  define _IO_IN_BACKUP 0x100
+# endif
 # if !defined _IO_LINE_BUF
 #  define _IO_LINE_BUF 0x200
 # endif
-- 
2.49.0

>From 9c45ae967ccc8caadcdc30ac59ec641c889ecdd7 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 6 Apr 2025 20:08:25 -0700
Subject: [PATCH 4/4] fseterr: Port to recent Haiku snapshots.

* lib/fseterr.h (__fseterr): Provide missing declaration.
---
 ChangeLog     | 3 +++
 lib/fseterr.h | 5 +++++
 2 files changed, 8 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index d1a16e15da..b24c4d104b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2025-04-06  Collin Funk  <collin.fu...@gmail.com>
 
+	fseterr: Port to recent Haiku snapshots.
+	* lib/fseterr.h (__fseterr): Provide missing declaration.
+
 	fflush: Port to recent Haiku snapshots.
 	* lib/stdio-impl.h (_IO_IN_BACKUP) [__HAIKU__]: Define macros.
 	* lib/fflush.c (fp_) [!__HAIKU__]: Define to fp.
diff --git a/lib/fseterr.h b/lib/fseterr.h
index c0712a24fd..57c30ef3d7 100644
--- a/lib/fseterr.h
+++ b/lib/fseterr.h
@@ -30,6 +30,11 @@
 
 #if HAVE___FSETERR /* musl libc */
 
+/* Haiku has __fseterr but does not declare it.  */
+# if defined __HAIKU__
+extern void __fseterr (FILE *fp);
+# endif
+
 # include <stdio_ext.h>
 # define fseterr(fp) __fseterr (fp)
 
-- 
2.49.0

Reply via email to