From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6707 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: new getopt features committed Date: Wed, 10 Dec 2014 22:31:03 -0500 Message-ID: <20141211033103.GA8429@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1418268684 6124 80.91.229.3 (11 Dec 2014 03:31:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Dec 2014 03:31:24 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6720-gllmg-musl=m.gmane.org@lists.openwall.com Thu Dec 11 04:31:18 2014 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1XyuTF-0003I6-Ce for gllmg-musl@m.gmane.org; Thu, 11 Dec 2014 04:31:17 +0100 Original-Received: (qmail 30053 invoked by uid 550); 11 Dec 2014 03:31:16 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 30045 invoked from network); 11 Dec 2014 03:31:15 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:6707 Archived-At: I've just committed support for options after non-option arguments ("argv permutation" ala GNU getopt) in getopt_long only (same way it works on BSD -- plain getopt is always POSIX conforming but getopt_long has the new feature) and abbreviated long options. Hopefully this eliminates the need to patch libc (like Alpine is doing up til now) or individual apps (like some other dists are doing) with an alternate getopt implementation. A couple differences from GNU and BSD variants: - The code in musl now does not honor $POSIXLY_CORRECT. The only way to suppress argv permutation in getopt_long is with a leading '+' in the optstring. This may be changed depending on feedback. - The progression of optind is different, and IMO much less counter-intuitive, when options after non-option arguments are being processed. But the final argv[] order and final optind after getopt_long returns -1 should be the same. - No additional internal state is kept for non-option argument skipping. As a result, more passes over argv[] are needed in some cases, but it shouldn't make a practical performance difference. - Reporting of errors may be different; this is unintentional and should be fixed. In particular getopt_long does not print any messages for long option errors; only short options (handled by getopt internally) produce messages. Return values may be different too. If there are any regressions, let me know. Rich