From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10630 Path: news.gmane.org!.POSTED!not-for-mail From: Daniel Sabogal Newsgroups: gmane.linux.lib.musl.general Subject: Re: getopt_long_only Date: Thu, 13 Oct 2016 13:43:28 -0400 Message-ID: References: <002301d22560$0d79a610$286cf230$@codeaurora.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1476380644 20960 195.159.176.226 (13 Oct 2016 17:44:04 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 13 Oct 2016 17:44:04 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-10643-gllmg-musl=m.gmane.org@lists.openwall.com Thu Oct 13 19:43:57 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 1buk2g-0002qs-Bo for gllmg-musl@m.gmane.org; Thu, 13 Oct 2016 19:43:42 +0200 Original-Received: (qmail 23638 invoked by uid 550); 13 Oct 2016 17:43:41 -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 23617 invoked from network); 13 Oct 2016 17:43:41 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=DhTJOCbeOo94oy1aK6dgm1fUyilGDcpeHIYe8hydYB8=; b=ju3DKIzuOfcrXMxEHC62qKyMW+CV/TRdjdXlUP7jsvGHynLtB1kt63PYDe85VA2ITM VMRNjDomWhBgHGz4KJNSZruU6RZHrDk/cfQIP70+oHjD3s+g5h81lNnWWBaRphcv0f20 oMUr3yn3htt8e7mZ8QG1CyD6n2RkzdZMspGGQx6whCyDnOkUC3GG+j7IUZ1S9aZz19W+ VQ3S+y4RoMROVgJz3fPLg0kimPbukOUQMZyuXQcnWFs8jGWH7M/KF6tToiVWuRqBegxv o/Zpe1bZQrwe4pFmlsdRPMMiVPMXk2B37jCnSaWImvsNk8vnl99pewPrVTDcOxEpK2LG jzfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=DhTJOCbeOo94oy1aK6dgm1fUyilGDcpeHIYe8hydYB8=; b=U1bnrGFZ/nIfotzALHIENeAMGWQavR3vSqA23BOm9DuRu35UKtNgukbM8HqiMiOzUK be3HaAv+pz9ofgTFYzLF6zDTlZp6zgu6TlZg83XHn3JM5hrKgEQZzGh5FAptvefDrqM8 Hkrg2RvvIT2GaN/iEEm0+JSQrEXVNnc3hCdZU5E83fzsDcIdyjUtCIetPOhUVwUMXg2K F4vUZ2Vw+MHXJdtfmgG5DrRNUUExTU/xtx9DJB/8GSj+JnsnZq3yfpMxNFZWRPq6VIV3 v1OO9U2XI05Jg0Dcxjn93dEoSTBCEthBdlaFdB4CUonAQ+lY+VpiGrCNvThOUnYYRvT0 7NAg== X-Gm-Message-State: AA6/9RnjNoxoO6CnkZE5N1ZNaH0QNYRHaAXcq4iBNm99JySubDHlbXth0yz3JvITL0MvuEsj2Z4d9nmTMGNyVw== X-Received: by 10.202.189.133 with SMTP id n127mr5305921oif.49.1476380609095; Thu, 13 Oct 2016 10:43:29 -0700 (PDT) In-Reply-To: <002301d22560$0d79a610$286cf230$@codeaurora.org> Xref: news.gmane.org gmane.linux.lib.musl.general:10630 Archived-At: On Thu, Oct 13, 2016 at 10:42 AM, Sidney Manning wrote: > 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]=='-']==':' This will break getopt_long() since the entire condition won't hold whenever !longonly. I think just changing the longonly case to the following is sufficient. (longonly && argv[optind][1] && argv[optind][1] != '-')