From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10631 Path: news.gmane.org!.POSTED!not-for-mail From: "Sidney Manning" Newsgroups: gmane.linux.lib.musl.general Subject: RE: getopt_long_only Date: Thu, 13 Oct 2016 13:03:16 -0500 Message-ID: <00da01d2257c$131680e0$394382a0$@codeaurora.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1476381830 16281 195.159.176.226 (13 Oct 2016 18:03:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 13 Oct 2016 18:03:50 +0000 (UTC) To: Original-X-From: musl-return-10644-gllmg-musl=m.gmane.org@lists.openwall.com Thu Oct 13 20:03:47 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 1bukM5-0003hT-IF for gllmg-musl@m.gmane.org; Thu, 13 Oct 2016 20:03:45 +0200 Original-Received: (qmail 1743 invoked by uid 550); 13 Oct 2016 18:03:45 -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 1656 invoked from network); 13 Oct 2016 18:03:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1476381797; bh=wmjnn2hS0YOyQCbfpXvQ7y1BxhiSN8JzpYp50wK/oJc=; h=From:To:References:In-Reply-To:Subject:Date:From; b=eIogGsdmGDfZiNwdWZs5biNTczvlmsvKKlfPCWCXjCdAHpR1mnroKzLF5g7ByNJe+ y9bgqq+oIi57oDDnTPKpuCirPVp69/10TdEaTBl6ycgG9pjSEnzhnTGPcg7TMbf6nr CWsuL0JxXNHB6D6rcpHESZ4olL+V8ZdJPqz3xLgo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1476381797; bh=wmjnn2hS0YOyQCbfpXvQ7y1BxhiSN8JzpYp50wK/oJc=; h=From:To:References:In-Reply-To:Subject:Date:From; b=eIogGsdmGDfZiNwdWZs5biNTczvlmsvKKlfPCWCXjCdAHpR1mnroKzLF5g7ByNJe+ y9bgqq+oIi57oDDnTPKpuCirPVp69/10TdEaTBl6ycgG9pjSEnzhnTGPcg7TMbf6nr CWsuL0JxXNHB6D6rcpHESZ4olL+V8ZdJPqz3xLgo= DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org 48E3A61831 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 Original-References: In-Reply-To: X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQHKi3CbgleNZH0ti4Aj0oyT55MmKaC13i2g Content-Language: en-us Xref: news.gmane.org gmane.linux.lib.musl.general:10631 Archived-At: > -----Original Message----- > From: Sidney Manning [mailto:sidneym@codeaurora.org] > Sent: Thursday, October 13, 2016 9:43 AM > To: 'musl@lists.openwall.com' > Subject: getopt_long_only > > 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]) && It was pointed out to me that, "--" is a special case and should be treated as such (and the above change is wrong) --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -52,6 +52,10 @@ static int __getopt_long(int argc, char *const *argv, const char *optstring, con static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly) { optarg = 0; + if (longopts && argv[optind][0] == '-' && argv[optind][1] == '-' && + !argv[optind][2]) + return getopt(argc, argv, optstring); + if (longopts && argv[optind][0] == '-' && ((longonly && argv[optind][1]) || (argv[optind][1] == '-' && argv[optind][2]))) Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation