From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10629 Path: news.gmane.org!.POSTED!not-for-mail From: "Sidney Manning" Newsgroups: gmane.linux.lib.musl.general Subject: getopt_long_only Date: Thu, 13 Oct 2016 09:42:40 -0500 Message-ID: <002301d22560$0d79a610$286cf230$@codeaurora.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0024_01D22536.24A3C520" X-Trace: blaine.gmane.org 1476369805 11312 195.159.176.226 (13 Oct 2016 14:43:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 13 Oct 2016 14:43:25 +0000 (UTC) To: Original-X-From: musl-return-10642-gllmg-musl=m.gmane.org@lists.openwall.com Thu Oct 13 16:43:21 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1buhDm-0008Pj-68 for gllmg-musl@m.gmane.org; Thu, 13 Oct 2016 16:42:58 +0200 Original-Received: (qmail 3825 invoked by uid 550); 13 Oct 2016 14:42:57 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 3796 invoked from network); 13 Oct 2016 14:42:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1476369762; bh=fTlDadohRnOsSNUK9w01s7pp3wgUZl+Ri1C9Lp1Wy+E=; h=From:To:Subject:Date:From; b=DZypKvDDVlwF+w/9Me2jS355njxTJHk/FNKYIUjZDNvbGbO0Hxh66MMxUTVdKou4u 3lcrWB+PeWNTOXVTcBnu5hL5VYBVUJUjJx1Js746hbMDywEgmuw9Eyl9aYtsrerHQB tSkbu14/JMrHlOXPJwfUacZGc/hMuJnbSXptoavs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1476369762; bh=fTlDadohRnOsSNUK9w01s7pp3wgUZl+Ri1C9Lp1Wy+E=; h=From:To:Subject:Date:From; b=DZypKvDDVlwF+w/9Me2jS355njxTJHk/FNKYIUjZDNvbGbO0Hxh66MMxUTVdKou4u 3lcrWB+PeWNTOXVTcBnu5hL5VYBVUJUjJx1Js746hbMDywEgmuw9Eyl9aYtsrerHQB tSkbu14/JMrHlOXPJwfUacZGc/hMuJnbSXptoavs= DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org E7CE661802 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=sidneym@codeaurora.org X-Mailer: Microsoft Outlook 15.0 Thread-Index: AdIlVCwFyOLMMce4QkW2eyGHt7Hezw== Content-Language: en-us Xref: news.gmane.org gmane.linux.lib.musl.general:10629 Archived-At: This is a multipart message in MIME format. ------=_NextPart_000_0024_01D22536.24A3C520 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit I may have found an issue with this API. When a double hyphen is encountered the API is supposed to return a -1 but I'm seeing a '?'. My reference is from the Solaris docs which say: "The special option "--" can be used to delimit the end of the options; when it is encountered, -1 is returned and "--" is skipped. I attached a test case to show the problem. I made the following change it will cause the code to punt to getopt when just a "--" is found: argv[optind][0] == '-' argv[optind][1] == '-' argv[optind][2] == NULL diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index 480c001..9764f56 100644 --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -53,7 +53,7 @@ static int __getopt_long_core(int argc, char *const *argv, con { optarg = 0; if (longopts && argv[optind][0] == '-' && - ((longonly && argv[optind][1]) || + ((longonly && argv[optind][1]) && (argv[optind][1] == '-' && argv[optind][2]))) { int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':' Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation ------=_NextPart_000_0024_01D22536.24A3C520 Content-Type: text/plain; name="getopt.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="getopt.c" #define _GNU_SOURCE=0A= #include =0A= #include =0A= #include =0A= =0A= struct option options[] =3D=0A= {=0A= {=0A= "stop-at-entry", 0, 0, 's'=0A= },=0A= {=0A= "shell", 1, 0, 'c'=0A= },=0A= {=0A= NULL, 0, 0, 0=0A= }=0A= };=0A= =0A= extern int optreset;=0A= int main(void)=0A= {=0A= int val;=0A= optind =3D 1;=0A= //optreset =3D 1;=0A= =0A= int argc =3D 3;=0A= char *argv[] =3D {"dummy_arg", "--shell=3D/bin/sh", "--", NULL};=0A= int longindex =3D -1;=0A= char *optstring =3D "sc::";=0A= =0A= printf("**optind is %d, argv[%d] is %s\n", optind, optind, = argv[optind]);=0A= val =3D getopt_long_only(argc, argv, optstring, &options[0], = &longindex);=0A= if (val !=3D 'c') {=0A= printf ("%d: getopt_long_only FAIL\n", __LINE__);=0A= return 1;=0A= }=0A= printf("**optind is %d, argv[%d] is %s\n", optind, optind, = argv[optind]);=0A= val =3D getopt_long_only(argc, argv, optstring, &options[0], = &longindex);=0A= if (val !=3D -1) {=0A= printf ("%d: getopt_long_only FAIL\n", __LINE__);=0A= return 1;=0A= }=0A= return 0;=0A= }=0A= ------=_NextPart_000_0024_01D22536.24A3C520--