Commit 76d74c1a authored by Niels Möller's avatar Niels Möller

Updated getopt files, from glibc-2.19.

parent 56e05f0b
...@@ -3,6 +3,12 @@ ...@@ -3,6 +3,12 @@
* testsuite/nettle-pbkdf2-test: Avoid the bash construction * testsuite/nettle-pbkdf2-test: Avoid the bash construction
${#foo}. ${#foo}.
* getopt.c: Copied from glibc tree, tag glibc-2.19.
* getopt.h: Likewise.
* getopt1.c: Likewise.
* getopt_int.h: New file, also copied from glibc.
* Makefile.in (DISTFILES): Added getopt_int.h.
2014-05-09 Niels Möller <nisse@lysator.liu.se> 2014-05-09 Niels Möller <nisse@lysator.liu.se>
* mini-gmp.c: Updated, use version from gmp-6.0.0. * mini-gmp.c: Updated, use version from gmp-6.0.0.
......
...@@ -191,7 +191,8 @@ SOURCES = $(nettle_SOURCES) $(hogweed_SOURCES) \ ...@@ -191,7 +191,8 @@ SOURCES = $(nettle_SOURCES) $(hogweed_SOURCES) \
$(getopt_SOURCES) $(internal_SOURCES) \ $(getopt_SOURCES) $(internal_SOURCES) \
aesdata.c desdata.c twofishdata.c shadata.c gcmdata.c eccdata.c aesdata.c desdata.c twofishdata.c shadata.c gcmdata.c eccdata.c
DISTFILES = $(SOURCES) $(HEADERS) getopt.h .bootstrap run-tests \ DISTFILES = $(SOURCES) $(HEADERS) getopt.h getopt_int.h \
.bootstrap run-tests \
aclocal.m4 configure.ac \ aclocal.m4 configure.ac \
configure stamp-h.in \ configure stamp-h.in \
config.guess config.sub install-sh texinfo.tex \ config.guess config.sub install-sh texinfo.tex \
......
This diff is collapsed.
/* Declarations for getopt. /* Declarations for getopt.
Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc. Copyright (C) 1989-2014 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify The GNU C Library is free software; you can redistribute it and/or
it under the terms of the GNU General Public License as published by modify it under the terms of the GNU Lesser General Public
the Free Software Foundation; either version 2, or (at your option) License as published by the Free Software Foundation; either
any later version. version 2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. Lesser General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU Lesser General Public
along with this program; if not, write to the Free Software Foundation, License along with the GNU C Library; if not, see
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA. */ <http://www.gnu.org/licenses/>. */
#ifndef _GETOPT_H #ifndef _GETOPT_H
...@@ -33,6 +33,17 @@ ...@@ -33,6 +33,17 @@
# include <ctype.h> # include <ctype.h>
#endif #endif
#ifndef __THROW
# ifndef __GNUC_PREREQ
# define __GNUC_PREREQ(maj, min) (0)
# endif
# if defined __cplusplus && __GNUC_PREREQ (2,8)
# define __THROW throw ()
# else
# define __THROW
# endif
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
...@@ -92,11 +103,7 @@ extern int optopt; ...@@ -92,11 +103,7 @@ extern int optopt;
struct option struct option
{ {
# if (defined __STDC__ && __STDC__) || defined __cplusplus
const char *name; const char *name;
# else
char *name;
# endif
/* has_arg can't be an enum because some compilers complain about /* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */ type mismatches in all the code that assumes it is an int. */
int has_arg; int has_arg;
...@@ -136,38 +143,43 @@ struct option ...@@ -136,38 +143,43 @@ struct option
arguments to the option '\0'. This behavior is specific to the GNU arguments to the option '\0'. This behavior is specific to the GNU
`getopt'. */ `getopt'. */
#if (defined __STDC__ && __STDC__) || defined __cplusplus #ifdef __GNU_LIBRARY__
# ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with /* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */ errors, only prototype getopt for the GNU C library. */
extern int getopt (int argc, char *const *argv, const char *shortopts); extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
# else /* not __GNU_LIBRARY__ */ __THROW;
extern int getopt ();
# endif /* __GNU_LIBRARY__ */ # if defined __need_getopt && defined __USE_POSIX2 \
&& !defined __USE_POSIX_IMPLICITLY && !defined __USE_GNU
# ifndef __need_getopt /* The GNU getopt has more functionality than the standard version. The
extern int getopt_long (int argc, char *const *argv, const char *shortopts, additional functionality can be disable at runtime. This redirection
const struct option *longopts, int *longind); helps to also do this at runtime. */
extern int getopt_long_only (int argc, char *const *argv, # ifdef __REDIRECT
const char *shortopts, extern int __REDIRECT_NTH (getopt, (int ___argc, char *const *___argv,
const struct option *longopts, int *longind); const char *__shortopts),
__posix_getopt);
/* Internal only. Users should not call this directly. */ # else
extern int _getopt_internal (int argc, char *const *argv, extern int __posix_getopt (int ___argc, char *const *___argv,
const char *shortopts, const char *__shortopts) __THROW;
const struct option *longopts, int *longind, # define getopt __posix_getopt
int long_only); # endif
# endif # endif
#else /* not __STDC__ */ #else /* not __GNU_LIBRARY__ */
extern int getopt (); extern int getopt ();
# ifndef __need_getopt #endif /* __GNU_LIBRARY__ */
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal (); #ifndef __need_getopt
# endif extern int getopt_long (int ___argc, char *const *___argv,
#endif /* __STDC__ */ const char *__shortopts,
const struct option *__longopts, int *__longind)
__THROW;
extern int getopt_long_only (int ___argc, char *const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind)
__THROW;
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
......
/* getopt_long and getopt_long_only entry points for GNU getopt. /* getopt_long and getopt_long_only entry points for GNU getopt.
Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 Copyright (C) 1987-2014 Free Software Foundation, Inc.
Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify The GNU C Library is free software; you can redistribute it and/or
it under the terms of the GNU General Public License as published by modify it under the terms of the GNU Lesser General Public
the Free Software Foundation; either version 2, or (at your option) License as published by the Free Software Foundation; either
any later version. version 2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. Lesser General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU Lesser General Public
along with this program; if not, write to the Free Software Foundation, License along with the GNU C Library; if not, see
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA. */ <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif #endif
#include "getopt.h" #ifdef _LIBC
# include <getopt.h>
#if !defined __STDC__ || !__STDC__ #else
/* This is a separate conditional since some stdc systems # include "getopt.h"
reject `defined (const)'. */
#ifndef const
#define const
#endif
#endif #endif
#include "getopt_int.h"
#include <stdio.h> #include <stdio.h>
...@@ -63,14 +59,19 @@ ...@@ -63,14 +59,19 @@
#endif #endif
int int
getopt_long (argc, argv, options, long_options, opt_index) getopt_long (int argc, char *const *argv, const char *options,
int argc; const struct option *long_options, int *opt_index)
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
{ {
return _getopt_internal (argc, argv, options, long_options, opt_index, 0); return _getopt_internal (argc, argv, options, long_options, opt_index, 0, 0);
}
int
_getopt_long_r (int argc, char *const *argv, const char *options,
const struct option *long_options, int *opt_index,
struct _getopt_data *d)
{
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
0, d, 0);
} }
/* Like getopt_long, but '-' as well as '--' can indicate a long option. /* Like getopt_long, but '-' as well as '--' can indicate a long option.
...@@ -79,16 +80,20 @@ getopt_long (argc, argv, options, long_options, opt_index) ...@@ -79,16 +80,20 @@ getopt_long (argc, argv, options, long_options, opt_index)
instead. */ instead. */
int int
getopt_long_only (argc, argv, options, long_options, opt_index) getopt_long_only (int argc, char *const *argv, const char *options,
int argc; const struct option *long_options, int *opt_index)
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
{ {
return _getopt_internal (argc, argv, options, long_options, opt_index, 1); return _getopt_internal (argc, argv, options, long_options, opt_index, 1, 0);
} }
int
_getopt_long_only_r (int argc, char *const *argv, const char *options,
const struct option *long_options, int *opt_index,
struct _getopt_data *d)
{
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
1, d, 0);
}
#endif /* Not ELIDE_CODE. */ #endif /* Not ELIDE_CODE. */
...@@ -97,9 +102,7 @@ getopt_long_only (argc, argv, options, long_options, opt_index) ...@@ -97,9 +102,7 @@ getopt_long_only (argc, argv, options, long_options, opt_index)
#include <stdio.h> #include <stdio.h>
int int
main (argc, argv) main (int argc, char **argv)
int argc;
char **argv;
{ {
int c; int c;
int digit_optind = 0; int digit_optind = 0;
......
/* Internal declarations for getopt.
Copyright (C) 1989-2014 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef _GETOPT_INT_H
#define _GETOPT_INT_H 1
extern int _getopt_internal (int ___argc, char *const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only, int posixly_correct);
/* Reentrant versions which can handle parsing multiple argument
vectors at the same time. */
/* 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. */
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.
If this is zero, or a null string, it means resume the scan
by advancing to the next ARGV-element. */
char *__nextchar;
/* Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything,
the default is REQUIRE_ORDER if the environment variable
POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options;
stop option processing when the first non-option is seen.
This is what Unix does.
This mode of operation is selected by either setting the environment
variable POSIXLY_CORRECT, or using `+' as the first character
of the list of option characters.
PERMUTE is the default. We permute the contents of ARGV as we
scan, so that eventually all the non-options are at the end.
This allows options to be given in any order, even with programs
that were not written to expect this.
RETURN_IN_ORDER is an option available to programs that were
written to expect options and other ARGV-elements in any order
and that care about the ordering of the two. We describe each
non-option ARGV-element as if it were the argument of an option
with character code 1. Using `-' as the first character of the
list of option characters selects this mode of operation.
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. */
enum
{
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
} __ordering;
/* If the POSIXLY_CORRECT environment variable is set. */
int __posixly_correct;
/* Handle permutation of arguments. */
/* Describe the part of ARGV that contains non-options that have
been skipped. `first_nonopt' is the index in ARGV of the first
of them; `last_nonopt' is the index after the last of them. */
int __first_nonopt;
int __last_nonopt;
#if defined _LIBC && defined USE_NONOPTION_FLAGS
int __nonoption_flags_max_len;
int __nonoption_flags_len;
# endif
};
/* The initializer is necessary to set OPTIND and OPTERR to their
default values and to clear the initialization flag. */
#define _GETOPT_DATA_INITIALIZER { 1, 1 }
extern int _getopt_internal_r (int ___argc, char *const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only, struct _getopt_data *__data,
int posixly_correct);
extern int _getopt_long_r (int ___argc, char *const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
struct _getopt_data *__data);
extern int _getopt_long_only_r (int ___argc, char *const *___argv,
const char *__shortopts,
const struct option *__longopts,
int *__longind,
struct _getopt_data *__data);
#endif /* getopt_int.h */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment