[{"id":3676516,"web_url":"http://patchwork.ozlabs.org/comment/3676516/","msgid":"<adyegeRXhllwZwA_@waldemar-brodkorb.de>","list_archive_url":null,"date":"2026-04-13T07:42:57","subject":"[uclibc-ng-devel] Re: [PATCH v1] getopt-susv3: add support for\n reseting the\n scan by setting optind to zero","submitter":{"id":68677,"url":"http://patchwork.ozlabs.org/api/people/68677/","name":"Waldemar Brodkorb","email":"wbx@uclibc-ng.org"},"content":"Hi Charles,\n\nthanks a lot for the patch, applied and pushed.\n\nbest regards\n Waldemar\n\nCharles Mirabile wrote,\n\n> Busybox (among other programs) relies on the ability to reset arg scanning\n> by setting optind to zero. POSIX says that the behavior of getopt upon\n> encountering optind == 0 is unspecified, but glibc introduced the idea of\n> using it as a reset indicator, and enough programs do it that essentially\n> all libcs (musl, dietlibc, picolibc, and libcs from {Open,Net}BSD) have\n> adopted the convention (even if begrudgingly so).\n> \n> Signed-off-by: Charles Mirabile <cmirabil@redhat.com>\n> ---\n>  libc/unistd/getopt-susv3.c | 9 +++++++++\n>  1 file changed, 9 insertions(+)\n> \n> diff --git a/libc/unistd/getopt-susv3.c b/libc/unistd/getopt-susv3.c\n> index 7bed356f0..b7b236a6a 100644\n> --- a/libc/unistd/getopt-susv3.c\n> +++ b/libc/unistd/getopt-susv3.c\n> @@ -46,6 +46,15 @@ int getopt(int argc, char * const argv[], const char *optstring)\n>  \toptopt = 0;\n>  \toptarg = NULL;\n>  \n> +\t/*\n> +\t * POSIX says behavior when optind == 0 is unspecified, but other\n> +\t * libcs use this wiggle room to allow reseting getopt; we can too\n> +\t */\n> +\tif (!optind) {\n> +\t\to = NULL;\n> +\t\toptind = 1;\n> +\t}\n> +\n>  \tif (!o) {\t\t\t\t/* Not in a multi-option arg. */\n>  \t\tif ((optind >= argc)\t/* No more args? */\n>  \t\t\t|| ((p = argv[optind]) == NULL) /* Missing? */\n> -- \n> 2.53.0\n> \n> _______________________________________________\n> devel mailing list -- devel@uclibc-ng.org\n> To unsubscribe send an email to devel-leave@uclibc-ng.org\n>","headers":{"Return-Path":"<devel-bounces@uclibc-ng.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":"legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=uclibc-ng.org\n (client-ip=89.238.66.15; helo=helium.openadk.org;\n envelope-from=devel-bounces@uclibc-ng.org; receiver=patchwork.ozlabs.org)","Received":["from helium.openadk.org (helium.openadk.org [89.238.66.15])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fvKC037ggz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 13 Apr 2026 17:43:08 +1000 (AEST)","from helium.openadk.org (localhost [127.0.0.1])\n\tby helium.openadk.org (Postfix) with ESMTP id 2616C31E0CFD;\n\tMon, 13 Apr 2026 09:43:02 +0200 (CEST)","by helium.openadk.org (Postfix, from userid 1000)\n\tid D04BC31E0CAD; Mon, 13 Apr 2026 09:42:57 +0200 (CEST)"],"Date":"Mon, 13 Apr 2026 09:42:57 +0200","From":"Waldemar Brodkorb <wbx@uclibc-ng.org>","To":"Charles Mirabile <cmirabil@redhat.com>","Message-ID":"<adyegeRXhllwZwA_@waldemar-brodkorb.de>","References":"<20260409052509.2871272-1-cmirabil@redhat.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20260409052509.2871272-1-cmirabil@redhat.com>","X-Operating-System":"Linux 6.12.63+deb13-amd64 x86_64","Message-ID-Hash":"BANDTIGAFTN3AMLRWZUSKW4KOXPMAWCJ","X-Message-ID-Hash":"BANDTIGAFTN3AMLRWZUSKW4KOXPMAWCJ","X-MailFrom":"wbx@uclibc-ng.org","X-Mailman-Rule-Misses":"dmarc-mitigation; no-senders; approved; loop;\n banned-address; emergency; member-moderation; nonmember-moderation;\n administrivia; implicit-dest; max-recipients; max-size; news-moderation;\n no-subject; digests; suspicious-header","CC":"devel@uclibc-ng.org","X-Mailman-Version":"3.3.10","Precedence":"list","Subject":"[uclibc-ng-devel] Re: [PATCH v1] getopt-susv3: add support for\n reseting the\n scan by setting optind to zero","List-Id":"uClibc-ng Development <devel.uclibc-ng.org>","Archived-At":"\n <https://uclibc-ng.org/mailman3/hyperkitty/list/devel@uclibc-ng.org/message/BANDTIGAFTN3AMLRWZUSKW4KOXPMAWCJ/>","List-Archive":"\n <https://uclibc-ng.org/mailman3/hyperkitty/list/devel@uclibc-ng.org/>","List-Help":"<mailto:devel-request@uclibc-ng.org?subject=help>","List-Owner":"<mailto:devel-owner@uclibc-ng.org>","List-Post":"<mailto:devel@uclibc-ng.org>","List-Subscribe":"<mailto:devel-join@uclibc-ng.org>","List-Unsubscribe":"<mailto:devel-leave@uclibc-ng.org>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit"}}]