diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2015-09-12 14:48:15 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2015-09-12 14:48:15 +0000 |
commit | 708d74d49280694cfab20a17028e578ec48fe52f (patch) | |
tree | 599f4e398b85e2b12c4b420b04c47a826c34f3e9 /lib | |
parent | 2a59fd816d03d6c262dc9b4eeec61b4668ecb126 (diff) |
Wrap <getopt.h> to make the functions weak and make access to the initialized
variables go direct. (Common variables cannot be aliased.)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/hidden/getopt.h | 37 | ||||
-rw-r--r-- | lib/libc/stdlib/getopt_long.c | 7 |
2 files changed, 43 insertions, 1 deletions
diff --git a/lib/libc/hidden/getopt.h b/lib/libc/hidden/getopt.h new file mode 100644 index 00000000000..167af2db749 --- /dev/null +++ b/lib/libc/hidden/getopt.h @@ -0,0 +1,37 @@ +/* $OpenBSD: getopt.h,v 1.1 2015/09/12 14:48:14 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _LIBC_GETOPT_H_ +#define _LIBC_GETOPT_H_ + +#include_next <getopt.h> + +extern PROTO_NORMAL(opterr); +extern PROTO_NORMAL(optind); +extern PROTO_NORMAL(optopt); + +#if 0 +/* alas, COMMON symbols alias differently */ +extern PROTO_NORMAL(optarg); +extern PROTO_NORMAL(optreset); +#endif + +PROTO_DEPRECATED(getopt); +PROTO_DEPRECATED(getopt_long); +PROTO_DEPRECATED(getopt_long_only); + +#endif /* !_LIBC_GETOPT_H_ */ diff --git a/lib/libc/stdlib/getopt_long.c b/lib/libc/stdlib/getopt_long.c index f46cd8bf4e4..21407824ddf 100644 --- a/lib/libc/stdlib/getopt_long.c +++ b/lib/libc/stdlib/getopt_long.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getopt_long.c,v 1.26 2013/06/08 22:47:56 millert Exp $ */ +/* $OpenBSD: getopt_long.c,v 1.27 2015/09/12 14:48:14 guenther Exp $ */ /* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ /* @@ -61,6 +61,11 @@ int optopt = '?'; /* character checked for validity */ int optreset; /* reset getopt */ char *optarg; /* argument associated with option */ +/* DEF_* only work on initialized (non-COMMON) variables */ +DEF_WEAK(opterr); +DEF_WEAK(optind); +DEF_WEAK(optopt); + #define PRINT_ERROR ((opterr) && (*options != ':')) #define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */ |