From 6f6e523bf907adaf570e271f736cf64f3d1f313d Mon Sep 17 00:00:00 2001 From: "tbullock@comlore.com" Date: Thu, 17 Feb 2011 03:24:54 +0000 Subject: [PATCH] Portablelize new getopt.c so it should work where err.h is missing --- httperf/src/lib/getopt.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/httperf/src/lib/getopt.c b/httperf/src/lib/getopt.c index d6757a1..ee47ee6 100755 --- a/httperf/src/lib/getopt.c +++ b/httperf/src/lib/getopt.c @@ -25,7 +25,7 @@ * by Dieter Baron and Thomas Klausner. * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions + * MODIFICATION, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. @@ -46,9 +46,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include "getopt.h" +#include #include #include @@ -195,8 +195,9 @@ parse_long_options(char * const *nargv, const char *options, else { /* ambiguous abbreviation */ if (PRINT_ERROR) - warnx(ambig, (int)current_argv_len, - current_argv); + fprintf(stderr, "ambiguous option -- %.*s\n" + , (int)current_argv_len, + current_argv); optopt = 0; return (BADCH); } @@ -205,8 +206,10 @@ parse_long_options(char * const *nargv, const char *options, if (long_options[match].has_arg == no_argument && has_equal) { if (PRINT_ERROR) - warnx(noarg, (int)current_argv_len, - current_argv); + fprintf(stderr, "option doesn't take an " + "argument -- %.*s\n", + (int)current_argv_len, + current_argv); /* * XXX: GNU sets optopt to val regardless of flag */ @@ -235,8 +238,9 @@ parse_long_options(char * const *nargv, const char *options, * should be generated. */ if (PRINT_ERROR) - warnx(recargstring, - current_argv); + fprintf(stderr, "option requires an argument " + "-- %s\n", + current_argv); /* * XXX: GNU sets optopt to val regardless of flag */ @@ -253,7 +257,7 @@ parse_long_options(char * const *nargv, const char *options, return (-1); } if (PRINT_ERROR) - warnx(illoptstring, current_argv); + fprintf(stderr, "unknown option -- %s\n", current_argv); optopt = 0; return (BADCH); } @@ -415,7 +419,7 @@ start: if (!*place) ++optind; if (PRINT_ERROR) - warnx(illoptchar, optchar); + fprintf(stderr, "unknown option -- %c\n", optchar); optopt = optchar; return (BADCH); } @@ -426,7 +430,8 @@ start: else if (++optind >= nargc) { /* no arg */ place = EMSG; if (PRINT_ERROR) - warnx(recargchar, optchar); + fprintf(stderr, "option requires an argument" + " -- %c\n", optchar); optopt = optchar; return (BADARG); } else /* white space */ @@ -447,7 +452,8 @@ start: if (++optind >= nargc) { /* no arg */ place = EMSG; if (PRINT_ERROR) - warnx(recargchar, optchar); + fprintf(stderr, "option requires an " + "argument -- %c\n", optchar); optopt = optchar; return (BADARG); } else