From 9d042171749b94510b071c9e800ed0d2a4e95bb9 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 25 May 2011 07:38:36 +0200 Subject: [PATCH] Map getopt to bsd_getopt if we are using the overlay This will ensure the code can safely and correctly use optreset transparently. --- include/bsd/getopt.h | 5 +++++ src/bsd_getopt.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/bsd/getopt.h b/include/bsd/getopt.h index d2963cb..ba2c4eb 100644 --- a/include/bsd/getopt.h +++ b/include/bsd/getopt.h @@ -39,6 +39,11 @@ __BEGIN_DECLS extern int optreset; +#ifdef LIBBSD_OVERLAY +#undef getopt +#define getopt(argc, argv, optstr) bsd_getopt(argc, argv, optstr) +#endif + int bsd_getopt (int, char **, char *); __END_DECLS diff --git a/src/bsd_getopt.c b/src/bsd_getopt.c index f5fb304..3e89817 100644 --- a/src/bsd_getopt.c +++ b/src/bsd_getopt.c @@ -36,5 +36,9 @@ bsd_getopt(int argc, char **argv, char *shortopts) optind = 0; } - return getopt(argc, argv, shortopts); + /* + * Make sure we are using the system getopt() and not a possible + * overlay macro. + */ + return (getopt)(argc, argv, shortopts); } -- 2.47.2