Re: Haiku fixes for for fseeko, fbufmode, fflush, and fseterr.

2025-04-08 Thread Collin Funk
Hi Bruno,

Bruno Haible  writes:

> Thanks a lot for this. Let me update some comments accordingly.

Thanks!

On the Haiku bug report, your input might be appreciated [1]. They want
to avoid issues if they break internal ABI.

I suggested adding __fbufmode, even though fbufmode is a Gnulib
function.

Do you recall the exact issues with their implementation of fseeko and
fflush? I didn't look into it much yesterday outside of ensuring the
tests passed after my changes.

If not, I can perform some tests later.

Collin

[1] https://dev.haiku-os.org/ticket/19479#comment:12



Re: Haiku fixes for for fseeko, fbufmode, fflush, and fseterr.

2025-04-07 Thread Bruno Haible via Gnulib discussion list
Collin Funk wrote:
> 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].

Thanks a lot for this. Let me update some comments accordingly.


2025-04-07  Bruno Haible  

stdioext: Update comments regarding Haiku.
* lib/fbufmode.c (fbufmode): Update comment.
* lib/fpending.c: Likewise.
* lib/freadable.c: Likewise.
* lib/freadahead.c: Likewise.
* lib/freadptr.c: Likewise.
* lib/freadseek.c (freadptrinc): Likewise.
* lib/fseterr.c: Likewise.
* lib/fwritable.c: Likewise.
* lib/fwriting.c: Likewise.

diff --git a/lib/fbufmode.c b/lib/fbufmode.c
index db0e6b456b..440f019ed1 100644
--- a/lib/fbufmode.c
+++ b/lib/fbufmode.c
@@ -38,7 +38,7 @@ fbufmode (FILE *fp)
 #  define fp_ fp
 # endif
   /* GNU libc, BeOS, Haiku, Linux libc5 */
-# if HAVE___FLBF/* glibc >= 2.2 */
+# if HAVE___FLBF/* glibc >= 2.2, Haiku >= hrev58760 */
   if (__flbf (fp))
 return _IOLBF;
 # else
diff --git a/lib/fpending.c b/lib/fpending.c
index 7614b60783..be8a987734 100644
--- a/lib/fpending.c
+++ b/lib/fpending.c
@@ -26,7 +26,7 @@
 
 /* This file is not used on systems that already have the __fpending function,
namely glibc >= 2.2, Solaris >= 7, UnixWare >= 7.1.4.MP4, Cygwin >= 1.7.34,
-   Android API >= 23.  */
+   Android API >= 23, musl libc, Haiku >= hrev58760.  */
 
 /* Return the number of pending (aka buffered, unflushed)
bytes on the stream, FP, that is open for writing.  */
diff --git a/lib/freadable.c b/lib/freadable.c
index 1366681dbf..2a494ae1ce 100644
--- a/lib/freadable.c
+++ b/lib/freadable.c
@@ -27,7 +27,7 @@
 
 /* This file is not used on systems that have the __freadable function,
namely glibc >= 2.2, Solaris >= 7, UnixWare >= 7.1.4.MP4, Cygwin >= 1.7.34,
-   Android API >= 23, musl libc.  */
+   Android API >= 23, musl libc, Haiku >= hrev58760.  */
 
 bool
 freadable (FILE *fp)
diff --git a/lib/freadahead.c b/lib/freadahead.c
index 83258f2f39..5a7da7c30b 100644
--- a/lib/freadahead.c
+++ b/lib/freadahead.c
@@ -28,7 +28,7 @@ extern size_t __sreadahead (FILE *);
 #endif
 
 /* This file is not used on systems that have the __freadahead function,
-   namely musl libc.  */
+   namely musl libc, Haiku >= hrev58760.  */
 
 size_t
 freadahead (FILE *fp)
diff --git a/lib/freadptr.c b/lib/freadptr.c
index 1c285c2e6d..bb56b47039 100644
--- a/lib/freadptr.c
+++ b/lib/freadptr.c
@@ -24,7 +24,7 @@
 #include "stdio-impl.h"
 
 /* This file is not used on systems that have the __freadptr function,
-   namely musl libc.  */
+   namely musl libc, Haiku >= hrev58760.  */
 
 const char *
 freadptr (FILE *fp, size_t *sizep)
diff --git a/lib/freadseek.c b/lib/freadseek.c
index 582400cbb6..1fcc8d255a 100644
--- a/lib/freadseek.c
+++ b/lib/freadseek.c
@@ -34,10 +34,10 @@ static void
 freadptrinc (FILE *fp, size_t increment)
 {
   /* Keep this code in sync with freadptr!  */
-#if HAVE___FREADPTRINC  /* musl libc */
+#if HAVE___FREADPTRINC  /* musl libc, Haiku >= hrev58760 */
   __freadptrinc (fp, increment);
 #elif defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
-  /* GNU libc, BeOS, Haiku, Linux libc5 */
+  /* GNU libc, BeOS, Haiku < hrev58760, Linux libc5 */
   fp->_IO_read_ptr += increment;
 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
   /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
diff --git a/lib/fseterr.c b/lib/fseterr.c
index a1279a553a..f66f30460a 100644
--- a/lib/fseterr.c
+++ b/lib/fseterr.c
@@ -24,7 +24,7 @@
 #include "stdio-impl.h"
 
 /* This file is not used on systems that have the __fseterr function,
-   namely musl libc.  */
+   namely musl libc, Haiku >= hrev58760.  */
 
 void
 fseterr (FILE *fp)
diff --git a/lib/fwritable.c b/lib/fwritable.c
index 4f512ec071..1f29f7f773 100644
--- a/lib/fwritable.c
+++ b/lib/fwritable.c
@@ -27,7 +27,7 @@
 
 /* This file 

Haiku fixes for for fseeko, fbufmode, fflush, and fseterr.

2025-04-06 Thread Collin Funk
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 
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  
+
+	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  
 
 	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__ >= 6) || 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 
+/* This FILE structure was made into an incomplete type in 2025.
+   See .  */
+#  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; \
+