shithub: rgbds

Download patch

ref: faa789376168f9af292c40285d1fa16767831cf1
parent: 648df0dc7d2e13753eef6a810b0ea085fa830aec
author: ISSOtm <[email protected]>
date: Fri Nov 8 19:47:45 EST 2019

Fix develop error in getopt_long_only
The error was due to casting `const` away for permuting argv
elements, which is necessary for a libc for compatibility with older
systems, but not for us.

Checkpatch will complain about the style not being followed, but this is not
our code, so it can be ignored.

--- a/include/extern/getopt.h
+++ b/include/extern/getopt.h
@@ -36,7 +36,7 @@
 	int val;
 };
 
-int getopt_long_only(int, char *const *, const char *, const struct option *, int *);
+int getopt_long_only(int, char **, const char *, const struct option *, int *);
 
 #define no_argument        0
 #define required_argument  1
--- a/src/extern/getopt.c
+++ b/src/extern/getopt.c
@@ -42,7 +42,7 @@
 	&& putc('\n', f));
 }
 
-static void permute(char *const *argv, int dest, int src)
+static void permute(char **argv, int dest, int src)
 {
 	char **av = (char **)argv;
 	char *tmp = av[src];
@@ -52,9 +52,9 @@
 	av[dest] = tmp;
 }
 
-static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly);
+static int __getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly);
 
-static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
+static int __getopt_long(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
 {
 	int ret, skipped, resumed;
 	if (!optind || __optreset) {
@@ -83,7 +83,7 @@
 	return ret;
 }
 
-static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
+static int __getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
 {
 	optarg = 0;
 	if (longopts && argv[optind][0] == '-' &&
@@ -170,7 +170,7 @@
 	return getopt(argc, argv, optstring);
 }
 
-int getopt_long_only(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx)
+int getopt_long_only(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx)
 {
 	return __getopt_long(argc, argv, optstring, longopts, idx, 1);
 }