[PATCH] fix build with gcc-15.0.1 error
[email protected] Thu, 3 Apr 2025 15:05:54 +0900
| Newsgroups | gmane.comp.gnu.utils.bugs |
|---|---|
| Message-ID | <[email protected]> |
From: "mark.yang" <[email protected]> * ../../sharutils-4.15.2/lib/system.h:51:36: error: expected ';', identifier or '(' before 'bool' 51 | typedef enum {false = 0, true = 1} bool; | ^~~~ ../../sharutils-4.15.2/lib/system.h:79:7: error: conflicting types for 'fdopen'; have 'FILE *(void)' 79 | FILE *fdopen (); | ^~~~~~ In file included from ../lib/stdio.h:43, from ../../sharutils-4.15.2/libopts/autoopts/options.h:42, from ../../sharutils-4.15.2/src/shar-opts.h:49: recipe-sysroot/usr/include/stdio.h:299:14: note: previous declaration of 'fdopen' with type 'FILE *(int, const char *)' 299 | extern FILE *fdopen (int __fd, const char *__modes) __THROW | ^~~~~~ ../../sharutils-4.15.2/lib/system.h:82:7: error: conflicting types for 'popen'; have 'FILE *(void)' 82 | FILE *popen (); | ^~~~~ recipe-sysroot/usr/include/stdio.h:893:14: note: previous declaration of 'popen' with type 'FILE *(const char *, const char *)' 893 | extern FILE *popen (const char *__command, const char *__modes) | ^~~~~ ../../sharutils-4.15.2/src/shar.c:112:12: error: conflicting types for 'localtime'; have 'struct tm *(void)' 112 | struct tm *localtime (); | ^~~~~~~~~ In file included from ../lib/time.h:39, from ../lib/sys/stat.h:44, from ../../sharutils-4.15.2/lib/system.h:32: recipe-sysroot/usr/include/time.h:136:19: note: previous declaration of 'localtime' with type 'struct tm *(const time_t *)' {aka 'struct tm *(const long int *)'} 136 | extern struct tm *localtime (const time_t *__timer) __THROW; | ^~~~~~~~~ ../../sharutils-4.15.2/src/uudecode.c:85:16: error: conflicting types for 'getpwnam'; have 'struct passwd *(void)' 85 | struct passwd *getpwnam (); | ^~~~~~~~ In file included from ../../sharutils-4.15.2/src/uudecode.c:76: recipe-sysroot/usr/include/pwd.h:116:23: note: previous declaration of 'getpwnam' with type 'struct passwd *(const char *)' 116 | extern struct passwd *getpwnam (const char *__name) __nonnull ((1)); | ^~~~~~~~ | ^~~~~~~~~ * gcc-15 uses gnu23 standard for c: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=55e3bd376b2214e200fa76d12b67ff259b06c212 bool is included as a reserved word, causing an error due to duplicate declaration. Also, when parameters are empty, an error occurs. Therefore, when using functions from the standard library, modify the defines in configure.ac and source code to use standard library functions. Signed-off-by: mark.yang <[email protected]> --- configure.ac | 2 +- lib/system.h | 6 ++++++ libopts/autoopts/options.h | 2 ++ libopts/compat/compat.h | 2 ++ src/shar.c | 2 ++ src/uudecode.c | 2 ++ 6 files changed, 15 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 2ccaac9..fa66368 100644 --- a/configure.ac +++ b/configure.ac @@ -73,7 +73,7 @@ AC_HEADER_STDC AC_STRUCT_TIMEZONE AC_TYPE_SIZE_T AC_TYPE_INTMAX_T -AC_CHECK_FUNCS([fchmod isascii strchr]) +AC_CHECK_FUNCS([fchmod isascii strchr fdopen popen localtime getpwnam]) AC_FUNC_CLOSEDIR_VOID AC_FUNC_FSEEKO AC_REPLACE_FUNCS([memset mktime strftime xmalloc xstrdup]) diff --git a/lib/system.h b/lib/system.h index 2b9846b..05864ac 100644 --- a/lib/system.h +++ b/lib/system.h @@ -48,7 +48,9 @@ typedef long intmax_t; #ifdef HAVE_STDBOOL_H #include <stdbool.h> #else +# if defined __STDC__ && defined __STDC_VERSION__ && __STDC_VERSION__ <= 201710L typedef enum {false = 0, true = 1} bool; +# endif #endif #if !HAVE_DECL_STRTOIMAX && !defined strtoimax @@ -75,8 +77,12 @@ intmax_t strtoimax (); # include <unistd.h> #endif +#ifndef HAVE_FDOPEN FILE *fdopen (); +#endif +#ifndef HAVE_POPEN FILE *popen (); +#endif /* Global functions of the shar package. */ diff --git a/libopts/autoopts/options.h b/libopts/autoopts/options.h index 0601d0f..2f86b5e 100644 --- a/libopts/autoopts/options.h +++ b/libopts/autoopts/options.h @@ -65,12 +65,14 @@ # if defined(HAVE_STDBOOL_H) # include <stdbool.h> # else +# if defined __STDC__ && defined __STDC_VERSION__ && __STDC_VERSION__ <= 201710L typedef enum { false = 0, true = 1 } _Bool; # define bool _Bool /* The other macros must be usable in preprocessor directives. */ # define false 0 # define true 1 +# endif # endif /* HAVE_SYSEXITS_H */ #endif /* COMPAT_H_GUARD */ // END-CONFIGURED-HEADERS diff --git a/libopts/compat/compat.h b/libopts/compat/compat.h index 561d55d..2ffea7e 100644 --- a/libopts/compat/compat.h +++ b/libopts/compat/compat.h @@ -185,12 +185,14 @@ #ifdef HAVE_STDBOOL_H # include <stdbool.h> #else +# if defined __STDC__ && defined __STDC_VERSION__ && __STDC_VERSION__ <= 201710L typedef enum { false = 0, true = 1 } _Bool; # define bool _Bool /* The other macros must be usable in preprocessor directives. */ # define false 0 # define true 1 +# endif #endif /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/src/shar.c b/src/shar.c index 6d7ed1d..af976ea 100644 --- a/src/shar.c +++ b/src/shar.c @@ -109,7 +109,9 @@ static inline unsigned char to_uchar (char ch) { return ch; } #define IS_GRAPH(_c) (isprint (to_uchar (_c)) && !isspace (to_uchar (_c))) #endif +#ifndef HAVE_LOCALTIME struct tm *localtime (); +#endif #if MSDOS /* 1 extra for CR. */ diff --git a/src/uudecode.c b/src/uudecode.c index 0621c99..00a6345 100644 --- a/src/uudecode.c +++ b/src/uudecode.c @@ -82,7 +82,9 @@ static char const cright_years_z[] = #define UU_CHMOD(_n, _fd, _m) chmod ((_n), UU_MODE_BITS(_m)) #endif +#ifndef HAVE_GETPWNAM struct passwd *getpwnam (); +#endif static uudecode_exit_code_t read_stduu( const char *inname, const char *outname);