[1/3] include/binary-io.h: guard O_BINARY usage with defined check

Message ID 20250914195345.366186-2-andrew@andrewhanson.dev
State New
Headers
Series Fix -Wundef warnings in include/ and bfd/ |

Commit Message

Andrew Hanson Sept. 14, 2025, 7:52 p.m. UTC
  Fixes -Wundef compiler warning when O_BINARY is not defined. Wrap the check
to ensure portability across platforms.
---
 include/binary-io.h | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Jan Beulich Sept. 15, 2025, 2:40 a.m. UTC | #1
On 14.09.2025 21:52, Andrew Hanson wrote:
> Fixes -Wundef compiler warning when O_BINARY is not defined. Wrap the check
> to ensure portability across platforms.
> ---
>  include/binary-io.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/include/binary-io.h b/include/binary-io.h
> index 2f4be43a7c1..33f5173636f 100644
> --- a/include/binary-io.h
> +++ b/include/binary-io.h
> @@ -34,6 +34,10 @@
>    /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect.  */
>  # undef O_BINARY
>  # undef O_TEXT
> +#endif
> +  /* If O_BINARY is not defined, provide a harmless default. */
> +#ifndef O_BINARY
> +# define O_BINARY 0
>  #endif
>  #if O_BINARY
>  # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__

It feels a little odd to define it to 0, just for it to then be
undef-ed again, to then be defined to 0 again. Imo it would be
more logical to change the #if line to include a defined() check.
Thoughts?

Jan
  

Patch

diff --git a/include/binary-io.h b/include/binary-io.h
index 2f4be43a7c1..33f5173636f 100644
--- a/include/binary-io.h
+++ b/include/binary-io.h
@@ -34,6 +34,10 @@ 
   /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect.  */
 # undef O_BINARY
 # undef O_TEXT
+#endif
+  /* If O_BINARY is not defined, provide a harmless default. */
+#ifndef O_BINARY
+# define O_BINARY 0
 #endif
 #if O_BINARY
 # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__