[PATCH] getopt,argp - reentrant getopt interface, argp fixes
Marcus Brinkmann
marcus.brinkmann@ruhr-uni-bochum.de
Sat Mar 6 20:36:00 GMT 2004
Small glitch in the changelog fixed, please use the ChangeLog entry below.
Thanks,
Marcus
2004-03-06 Marcus Brinkmann <marcus@gnu.org>
* posix/getopt.h (struct _getopt_data) [!__need_getopt]: New structure.
(_GETOPT_DATA_INITIALIZER) [!__need_getopt]: New macro.
(_getopt_internal_r) [!__need_getopt]: New declaration.
* posix/getopt.c (nextchar, ordering, posixly_correct,
first_nonopt, last_nonopt): Static variables removed.
(nonoption_flags_max_len, nonoption_flags_len) [_LIBC &&
USE_NONOPTION_FLAGS]: Static variables removed.
(getopt_data): New static variable.
(SWAP_FLAGS): Use d->__nonoption_flags_len instead
nonoption_flags_len.
(exchange): Add new argument D of type struct getopt_data *.
Replace optind with d->optind, optarg with d->optarg, opterr with
d->opterr, optopt with d->optopt, nextchar with d->__nextchar,
first_nonopt with d->__first_nonopt, last_nonopt with
d->__last_nonopt, d->ordering with d->__ordering,
d->posixly_correct with d->__posixly_correct (which is now an
int instead a string, so fix users), nonoption_flags_len
with d->__nonoption_flags_len, nonoption_flags_max_len with
d->__nonoption_flags_max_len.
(_getopt_initialize): Likewise.
(_getopt_internal): Rename to ...
(_getopt_internal_r): ... this. Also add new argument D of type
struct getopt_data * and use of members of D rather than global or
static variables as described for exchange() above. Add new argument
to invocations of _getopt_initialize and exchange.
(_getopt_internal): Reimplement in terms of _getopt_internal_r.
* posix/getopt1.c: Remove libc_hidden_def for getopt_long and
getopt_long_only.
(__getopt_long_r, __getopt_long_only_r): New functions.
* include/getopt.h: Remove libc_hidden_proto for getopt_long and
getopt_long_only.
(__getopt_long_r, __getopt_long_only_r): New prototypes.
* argp/argp-parse.c [_LIBC]: Do not include <bits/libc-lock.h>.
[!_LIBC && HAVE_CTHREADS_H]: Do not include <cthreads.h>.
[!_LIBC] (_argp_hang): Make static.
(getopt_lock, LOCK_GETOPT, UNLOCK_GETOPT): Remove.
(_argp_unlock_xxx): Remove.
(parser_init): Do not use LOCK_GETOPT.
(parser_finalize): Do not use UNLOCK_GETOPT.
(struct parser): New member OPT_DATA.
(parser_init): Initialize parser->opt_data. Use
parser->opt_data.opterr instead of opterr.
(parser_parse_opt): Use parser->opt_data.optarg instead optarg.
(parser_parse_next): Likewise. Use parser->opt_data.optind
instead optind. Use parser->opt_data.optopt instead of optopt.
Call __getopt_long_only_r and __getopt_long_r instead of
getopt_long_only and getopt_long, and pass the extra argument.
More information about the Libc-alpha
mailing list