]> git.saurik.com Git - apple/libc.git/blob - stdlib/FreeBSD/getopt.c.patch
Libc-763.11.tar.gz
[apple/libc.git] / stdlib / FreeBSD / getopt.c.patch
1 --- getopt.c.bsdnew 2009-11-13 14:11:48.000000000 -0800
2 +++ getopt.c 2009-11-13 14:11:48.000000000 -0800
3 @@ -44,16 +44,24 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/
4
5 #include "libc_private.h"
6
7 +#ifndef BUILDING_VARIANT
8 int opterr = 1, /* if error message should be printed */
9 optind = 1, /* index into parent argv vector */
10 optopt, /* character checked for validity */
11 optreset; /* reset getopt */
12 char *optarg; /* argument associated with option */
13 +#endif /* !BUILDING_VARIANT */
14
15 #define BADCH (int)'?'
16 #define BADARG (int)':'
17 #define EMSG ""
18
19 +#if __DARWIN_UNIX03
20 +#define PROGNAME nargv[0]
21 +#else
22 +#define PROGNAME _getprogname()
23 +#endif
24 +
25 /*
26 * getopt --
27 * Parse argc/argv argument vector.
28 @@ -99,8 +107,8 @@ getopt(nargc, nargv, ostr)
29 ++optind;
30 if (opterr && *ostr != ':')
31 (void)fprintf(stderr,
32 - "%s: illegal option -- %c\n", _getprogname(),
33 - optopt);
34 + "%s: illegal option -- %c\n",
35 + PROGNAME, optopt);
36 return (BADCH);
37 }
38
39 @@ -119,13 +127,19 @@ getopt(nargc, nargv, ostr)
40 optarg = nargv[optind];
41 else {
42 /* option-argument absent */
43 +#if __DARWIN_UNIX03
44 + /* Yes, the standard will put optind past the last
45 + argument */
46 + ++optind;
47 + optarg = NULL;
48 +#endif /* __DARWIN_UNIX03 */
49 place = EMSG;
50 if (*ostr == ':')
51 return (BADARG);
52 if (opterr)
53 (void)fprintf(stderr,
54 "%s: option requires an argument -- %c\n",
55 - _getprogname(), optopt);
56 + PROGNAME, optopt);
57 return (BADCH);
58 }
59 place = EMSG;