]> git.saurik.com Git - apple/libc.git/blame - stdlib/FreeBSD/getopt.c.patch
Libc-498.1.5.tar.gz
[apple/libc.git] / stdlib / FreeBSD / getopt.c.patch
CommitLineData
224c7076
A
1--- ../Libc/stdlib/FreeBSD/getopt.c 2004-11-25 11:38:41.000000000 -0800
2+++ getopt.c 2005-01-26 19:27:09.000000000 -0800
3@@ -48,16 +48,24 @@
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@@ -103,8 +111,8 @@
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@@ -123,13 +131,19 @@
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;