2026-07-17 Paul Eggert <eggert@cs.ucla.edu>
+ 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".
#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
#include <getopt.h>
#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);
}
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);
}