From: Paul Eggert Date: Fri, 17 Jul 2026 20:47:19 +0000 (-0700) Subject: getopt: port to NetBSD git head gcc -Wuseless cast X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a0cd9fd1fd032f775d4aada3469b29f9817c754d;p=thirdparty%2Fgnulib.git getopt: port to NetBSD git head gcc -Wuseless cast Problem reported by Thomas Klausner in: https://lists.gnu.org/r/emacs-devel/2026-07/msg00169.html * lib/getopt-pfx-ext.h (__getopt_argv_const_is_empty): New macro, defined to 1 when we define __getopt_argv_const to empty. * lib/getopt1.c (ARGV_CAST): New macro. (getopt_long, getopt_long_only): Use it. --- diff --git a/ChangeLog b/ChangeLog index d1ea69185f..224bcf30b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2026-07-17 Paul Eggert + getopt: port to NetBSD git head gcc -Wuseless cast + Problem reported by Thomas Klausner in: + https://lists.gnu.org/r/emacs-devel/2026-07/msg00169.html + * lib/getopt-pfx-ext.h (__getopt_argv_const_is_empty): New macro, + defined to 1 when we define __getopt_argv_const to empty. + * lib/getopt1.c (ARGV_CAST): New macro. + (getopt_long, getopt_long_only): Use it. + gendocs: output human-readable file sizes * build-aux/gendocs.sh (calcsize): Output human-readable file size, rather than always size in KiB mislabled as "K bytes". diff --git a/lib/getopt-pfx-ext.h b/lib/getopt-pfx-ext.h index db2e27f36c..189598a125 100644 --- a/lib/getopt-pfx-ext.h +++ b/lib/getopt-pfx-ext.h @@ -58,6 +58,7 @@ #ifndef __getopt_argv_const # if defined __GETOPT_PREFIX # define __getopt_argv_const /* empty */ +# define __getopt_argv_const_is_empty 1 # else # define __getopt_argv_const const # endif diff --git a/lib/getopt1.c b/lib/getopt1.c index a5f9988828..7a5ae1cad0 100644 --- a/lib/getopt1.c +++ b/lib/getopt1.c @@ -24,11 +24,19 @@ #include #include "getopt_int.h" +/* Convert char *__getopt_argv_const * to char ** without provoking + gcc -Wuseless-cast when __getopt_argv_gconst is empty. */ +#ifdef __getopt_argv_const_is_empty +# define ARGV_CAST(argv) (argv) +#else +# define ARGV_CAST(argv) ((char **) (argv)) +#endif + int getopt_long (int argc, char *__getopt_argv_const *argv, const char *options, const struct option *long_options, int *opt_index) { - return _getopt_internal (argc, (char **) argv, options, long_options, + return _getopt_internal (argc, ARGV_CAST (argv), options, long_options, opt_index, 0, 0); } @@ -51,7 +59,7 @@ getopt_long_only (int argc, char *__getopt_argv_const *argv, const char *options, const struct option *long_options, int *opt_index) { - return _getopt_internal (argc, (char **) argv, options, long_options, + return _getopt_internal (argc, ARGV_CAST (argv), options, long_options, opt_index, 1, 0); }