summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-05-20 20:32:27 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-05-20 20:32:27 +0000
commit43eb269ab1d216074e18dadc74c9671398dfe938 (patch)
tree937470bd2097d85323b2d1ae3eedde5734ed13d2 /libc
parent380783acef86885b2a3d8b9058598a2dd22e2dba (diff)
getopt: do not needlessly use static structure.
Reorder structure members and change some of them into smallints to reduce bss and text: text data bss dec hex filename - 2403 12 40 2455 997 libc/unistd/getopt.o + 2252 12 0 2264 8d8 libc/unistd/getopt.o
Diffstat (limited to 'libc')
-rw-r--r--libc/unistd/getopt.c6
-rw-r--r--libc/unistd/getopt_int.h32
2 files changed, 18 insertions, 20 deletions
diff --git a/libc/unistd/getopt.c b/libc/unistd/getopt.c
index 754e86f25..c28afda0d 100644
--- a/libc/unistd/getopt.c
+++ b/libc/unistd/getopt.c
@@ -162,10 +162,6 @@ int opterr = 1;
int optopt = '?';
-/* Keep a global copy of all internal members of getopt_data. */
-
-static struct _getopt_data getopt_data;
-
#ifndef __GNU_LIBRARY__
@@ -1158,7 +1154,9 @@ _getopt_internal (int argc, char *const *argv, const char *optstring,
const struct option *longopts, int *longind, int long_only)
{
int result;
+ struct _getopt_data getopt_data;
+ memset(&getopt_data, 0, sizeof(getopt_data));
getopt_data.optind = optind;
getopt_data.opterr = opterr;
diff --git a/libc/unistd/getopt_int.h b/libc/unistd/getopt_int.h
index e2a005db9..e26c7caba 100644
--- a/libc/unistd/getopt_int.h
+++ b/libc/unistd/getopt_int.h
@@ -30,29 +30,29 @@ extern int _getopt_internal (int ___argc, char *const *___argv,
/* Reentrant versions which can handle parsing multiple argument
vectors at the same time. */
+enum
+ {
+ REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
+ };
+
/* Data type for reentrant functions. */
struct _getopt_data
{
/* These have exactly the same meaning as the corresponding global
variables, except that they are used for the reentrant
versions of getopt. */
+ char *optarg;
int optind;
int opterr;
int optopt;
- char *optarg;
/* Internal members. */
/* True if the internal members have been initialized. */
- int __initialized;
-
- /* The next char to be scanned in the option-element
- in which the last option character we returned was found.
- This allows us to pick up the scan where we left off.
+ smallint __initialized;
- If this is zero, or a null string, it means resume the scan
- by advancing to the next ARGV-element. */
- char *__nextchar;
+ /* If the POSIXLY_CORRECT environment variable is set. */
+ smallint __posixly_correct;
/* Describe how to deal with options that follow non-option ARGV-elements.
@@ -82,15 +82,15 @@ struct _getopt_data
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' can cause `getopt' to return -1 with `optind' != ARGC. */
+ smallint __ordering;
- enum
- {
- REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
- } __ordering;
-
- /* If the POSIXLY_CORRECT environment variable is set. */
- int __posixly_correct;
+ /* The next char to be scanned in the option-element
+ in which the last option character we returned was found.
+ This allows us to pick up the scan where we left off.
+ If this is zero, or a null string, it means resume the scan
+ by advancing to the next ARGV-element. */
+ char *__nextchar;
/* Handle permutation of arguments. */