diff options
author | Zack Weinberg <zackw@panix.com> | 2017-04-01 12:11:33 -0400 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2017-04-07 07:50:06 -0400 |
commit | 7a7be6c9a2a89ac5783d4f27d67b0fae3218228f (patch) | |
tree | 924a9917be84855368ad0e4722b4694e29ecbe30 /posix/getopt1.c | |
parent | 544ce845def4540de11d9484df888df94876b14e (diff) | |
download | glibc-7a7be6c9a2a89ac5783d4f27d67b0fae3218228f.tar.gz glibc-7a7be6c9a2a89ac5783d4f27d67b0fae3218228f.tar.xz glibc-7a7be6c9a2a89ac5783d4f27d67b0fae3218228f.zip |
getopt: merge from gnulib: function prototype adjustments
For standards compliance, getopt, getopt_long, and getopt_long_only in glibc have to take 'char *const *argv' even though they can mutate the array. gnulib has tried to clean this up as much as possible: all the internal functions use 'char **argv', and when used standalone, so do getopt_long and getopt_long_only. Also brought over are __nonnull annotations, corrections to documentation, and apparently it is no longer necessary to worry about conflicting prototypes for getopt. The macroification of the definitions of getopt and __posix_getopt goes beyond what is currently in gnulib. At this point getopt1.c and getopt_int.h are identical to their gnulib versions. * posix/getopt.h: Add backup definition of __nonnull for consistency with gnulib. Define __getopt_argv_const to const if not already defined. (getopt): Update doc comment from gnulib. Prototype unconditionally. Add __nonnull annotation. (__posix_getopt): Add __nonnull annotation. (getopt_long, getopt_long_only): Use __getopt_argv_const in prototypes for consistency with gnulib. Add __nonnull annotations. * posix/getopt.c (_getopt_initialize, _getopt_internal_r) (getopt_internal): Change 'argv' argument to type 'char **'. Remove now-unnecessary casts. (getopt, __posix_getopt): Eliminate repetition with a macro. Cast 'argv' to 'char **' when calling _getopt_internal. * posix/getopt1.c (getopt_long, getopt_long_only): Use __getopt_argv_const for consistency with gnulib. Cast 'argv' to 'char **' when calling _getopt_internal. (_getopt_long_r, _getopt_long_only_r): Change 'argv' argument to type 'char **'. (main): Constify 'long_options'. * posix/getopt_int.h (getopt_internal, _getopt_internal_r) (_getopt_long_r, _getopt_long_only_r): Change 'argv' argument to type 'char **'.
Diffstat (limited to 'posix/getopt1.c')
-rw-r--r-- | posix/getopt1.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/posix/getopt1.c b/posix/getopt1.c index b4ae6e48f2..b967d24f57 100644 --- a/posix/getopt1.c +++ b/posix/getopt1.c @@ -24,14 +24,15 @@ #include "getopt_int.h" int -getopt_long (int argc, char *const *argv, const char *options, +getopt_long (int argc, char *__getopt_argv_const *argv, const char *options, const struct option *long_options, int *opt_index) { - return _getopt_internal (argc, argv, options, long_options, opt_index, 0, 0); + return _getopt_internal (argc, (char **) argv, options, long_options, + opt_index, 0, 0); } int -_getopt_long_r (int argc, char *const *argv, const char *options, +_getopt_long_r (int argc, char **argv, const char *options, const struct option *long_options, int *opt_index, struct _getopt_data *d) { @@ -45,14 +46,16 @@ _getopt_long_r (int argc, char *const *argv, const char *options, instead. */ int -getopt_long_only (int argc, char *const *argv, const char *options, +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, argv, options, long_options, opt_index, 1, 0); + return _getopt_internal (argc, (char **) argv, options, long_options, + opt_index, 1, 0); } int -_getopt_long_only_r (int argc, char *const *argv, const char *options, +_getopt_long_only_r (int argc, char **argv, const char *options, const struct option *long_options, int *opt_index, struct _getopt_data *d) { @@ -76,7 +79,7 @@ main (int argc, char **argv) { int this_option_optind = optind ? optind : 1; int option_index = 0; - static struct option long_options[] = + static const struct option long_options[] = { {"add", 1, 0, 0}, {"append", 0, 0, 0}, |