[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH 1/3] libbb: GETOPT_RESET macro
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2017-04-12 18:14:07
Message-ID: CAK1hOcNnLwX0959TJyDmm07UKp_4JPZSNAOXwZYFoz8aFeGPGA () mail ! gmail ! com
[Download RAW message or body]

On Tue, Apr 11, 2017 at 11:58 PM, Kaarle Ritvanen
<kaarle.ritvanen@datakunkku.fi> wrote:
> Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
> ---
>  include/libbb.h            | 19 +++++++++++++++++++
>  libbb/getopt32.c           |  8 +-------
>  libbb/vfork_daemon_rexec.c | 28 ++--------------------------
>  runit/sv.c                 |  7 +------
>  shell/shell_common.c       |  8 +-------
>  util-linux/getopt.c        |  7 +------
>  6 files changed, 25 insertions(+), 52 deletions(-)
>
> diff --git a/include/libbb.h b/include/libbb.h
> index 0407163..eb78619 100644
> --- a/include/libbb.h
> +++ b/include/libbb.h
> @@ -1178,6 +1178,25 @@ extern uint32_t option_mask32;
>  extern uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC;
>
>
> +/* BSD-derived getopt() functions require that optind be set to 1 in
> + * order to reset getopt() state.  This used to be generally accepted
> + * way of resetting getopt().  However, glibc's getopt()
> + * has additional getopt() state beyond optind, and requires that
> + * optind be set to zero to reset its state.  So the unfortunate state of
> + * affairs is that BSD-derived versions of getopt() misbehave if
> + * optind is set to 0 in order to reset getopt(), and glibc's getopt()
> + * will core dump if optind is set 1 in order to reset getopt().
> + *
> + * More modern versions of BSD require that optreset be set to 1 in
> + * order to reset getopt().  Sigh.  Standards, anyone?
> + */
> +#ifdef __GLIBC__
> +#define GETOPT_RESET optind = 0;
> +#else /* BSD style */
> +#define GETOPT_RESET optind = 1;
> +#endif

I think function-style macro is better:

+#ifdef __GLIBC__
+#define GETOPT_RESET() (optind = 0)
+#else /* BSD style */
+#define GETOPT_RESET() (optind = 1)
+#endif

Applied with this edit. Thanks.
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic