{"id":2221278,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2221278/?format=json","web_url":"http://patchwork.ozlabs.org/project/uclibc-ng/patch/20260409052509.2871272-1-cmirabil@redhat.com/","project":{"id":55,"url":"http://patchwork.ozlabs.org/api/1.2/projects/55/?format=json","name":"uClibc NG development","link_name":"uclibc-ng","list_id":"devel.uclibc-ng.org","list_email":"devel@uclibc-ng.org","web_url":"http://www.uclibc-ng.org","scm_url":"","webscm_url":"http://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260409052509.2871272-1-cmirabil@redhat.com>","list_archive_url":null,"date":"2026-04-09T05:25:09","name":"[uclibc-ng-devel,v1] getopt-susv3: add support for reseting the scan by setting optind to zero","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"b2f10da79a7d9be957936ad60bd71545dd2f171b","submitter":{"id":82370,"url":"http://patchwork.ozlabs.org/api/1.2/people/82370/?format=json","name":"Charles Mirabile","email":"cmirabil@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/uclibc-ng/patch/20260409052509.2871272-1-cmirabil@redhat.com/mbox/","series":[{"id":499236,"url":"http://patchwork.ozlabs.org/api/1.2/series/499236/?format=json","web_url":"http://patchwork.ozlabs.org/project/uclibc-ng/list/?series=499236","date":"2026-04-09T05:25:09","name":"[uclibc-ng-devel,v1] getopt-susv3: add support for reseting the scan by setting optind to zero","version":1,"mbox":"http://patchwork.ozlabs.org/series/499236/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2221278/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2221278/checks/","tags":{},"related":[],"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\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=FXOU9yzY;\n\tdkim-atps=neutral","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)","helium.openadk.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=FXOU9yzY;\n\tdkim-atps=neutral"],"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 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4frpKy1PKRz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 09 Apr 2026 15:25:25 +1000 (AEST)","from helium.openadk.org (localhost [127.0.0.1])\n\tby helium.openadk.org (Postfix) with ESMTP id 62EAB31E0CF8;\n\tThu, 09 Apr 2026 07:25:21 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby helium.openadk.org (Postfix) with ESMTPS id CF62931E04F5\n\tfor <devel@uclibc-ng.org>; Thu, 09 Apr 2026 07:25:15 +0200 (CEST)","from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-692-2TR7km9cMMW_KeIxutTy_A-1; Thu,\n 09 Apr 2026 01:25:13 -0400","from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 22E421800359\n\tfor <devel@uclibc-ng.org>; Thu,  9 Apr 2026 05:25:12 +0000 (UTC)","from cmirabil.redhat.com (unknown [10.2.16.23])\n\tby mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 91D8618002A6;\n\tThu,  9 Apr 2026 05:25:11 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1775712314;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\t to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\t content-transfer-encoding:content-transfer-encoding;\n\tbh=9U9tHlMzoG0Mb1aFEC7oRAOsKG44zS+PKLOBfwJqGXk=;\n\tb=FXOU9yzYi1VMd/+jXWY23n5hLajYjsG/cFWUnDCswrTxTPdP0UsOTSugQvaiUT+woEUP5W\n\tdJGvMpSofnMwUz652Mh3SAMi9n34ZqT385MsYjalXnlf4SuTPvxM0/HQB3yApkCwEfIffZ\n\tnP9fUVmfZoR8KRreKAkMIVROdK7xFz0=","X-MC-Unique":"2TR7km9cMMW_KeIxutTy_A-1","X-Mimecast-MFC-AGG-ID":"2TR7km9cMMW_KeIxutTy_A_1775712312","From":"Charles Mirabile <cmirabil@redhat.com>","To":"devel@uclibc-ng.org","Date":"Thu,  9 Apr 2026 01:25:09 -0400","Message-ID":"<20260409052509.2871272-1-cmirabil@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.111","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"0xl9ViX7nM4LsABKWm8QWVFbfAdNQDj4dKtXAvCHAEE_1775712312","X-Mimecast-Originator":"redhat.com","Message-ID-Hash":"VEXTV25NWKBW7TMHOFGTPZKGIWN6AUWH","X-Message-ID-Hash":"VEXTV25NWKBW7TMHOFGTPZKGIWN6AUWH","X-MailFrom":"cmirabil@redhat.com","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":"Charles Mirabile <cmirabil@redhat.com>","X-Mailman-Version":"3.3.10","Precedence":"list","Subject":"[uclibc-ng-devel] [PATCH v1] getopt-susv3: add support for reseting\n the scan\n 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/VEXTV25NWKBW7TMHOFGTPZKGIWN6AUWH/>","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\"; x-default=\"true\"","Content-Transfer-Encoding":"7bit"},"content":"Busybox (among other programs) relies on the ability to reset arg scanning\nby setting optind to zero. POSIX says that the behavior of getopt upon\nencountering optind == 0 is unspecified, but glibc introduced the idea of\nusing it as a reset indicator, and enough programs do it that essentially\nall libcs (musl, dietlibc, picolibc, and libcs from {Open,Net}BSD) have\nadopted the convention (even if begrudgingly so).\n\nSigned-off-by: Charles Mirabile <cmirabil@redhat.com>\n---\n libc/unistd/getopt-susv3.c | 9 +++++++++\n 1 file changed, 9 insertions(+)","diff":"diff --git a/libc/unistd/getopt-susv3.c b/libc/unistd/getopt-susv3.c\nindex 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","prefixes":["uclibc-ng-devel","v1"]}