View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0002016 | 1003.1(2024)/Issue8 | Base Definitions and Headers | public | 2026-12-01 23:00 | 2026-12-02 02:30 |
| Reporter | romanzilka | Assigned To | |||
| Priority | normal | Severity | Comment | Type | Enhancement Request |
| Status | New | Resolution | Open | ||
| Name | Roman Žilka | ||||
| Organization | |||||
| User Reference | |||||
| Section | 12.2 (Utility Syntax Guidelines) | ||||
| Page Number | 0 | ||||
| Line Number | 0 | ||||
| Interp Status | |||||
| Final Accepted Text | |||||
| Summary | 0002016: Utility Syntax Guidelines: Include long options as in GNU's getopt_long() | ||||
| Description | I propose extending subchapter 12.2 of the Base Definitions to include "long options", as implemented by the GNU C Library. Technical specifics: https://www.sourceware.org/glibc/manual/latest/html_node/Getopt-Long-Options.html https://man7.org/linux/man-pages/man3/getopt_long.3.html https://man7.org/linux/man-pages/man3/getopt_long_only.3.html If implemented, the function getopt_long() should be simultaneously incorporated into unistd.h (not getopt.h, as seen in glibc). The functionality of getopt_long_only() is equally desirable, but I suggest transforming it into a feature of getopt_long(), if possible. A feature which doesn't change the behavior of getopt_long() from the prespective of existing programs (expanding the expressiveness of has_arg in struct option, perhaps). Rationale: 1. Expanding the space of available options allows the application to assign more fitting options to its features. 2. Long options' names usually suggest their meaning, which is helpful to inexperienced and occasional users of the application. That includes the use of the long options in documentation. 3. Long options with no short counterparts can serve as a safety measure, making it very hard for the application user to activate a feature by accident. 4. The application may require more options than the alphanumeric repertoire of the Portable Character Set affords. 5. Long options with no short counterparts may be employed as markers of rarely used functionality, which may alleviate the difficulty of searching for an option in a list of all options. | ||||
| Desired Action | See Description. The present goal of this issue is to garner opinions and reach a yes/no verdict. | ||||
| Tags | No tags attached. | ||||
|
|
There are implementation differences am:ong them; eg https://man.openbsd.org/getopt_long I do not really grasp your 3., your 4. is not true for POSIX, having failed myself often i do not think 2. is true except you write entire sentences at times, and 5., well. Having said that i am all for supporting long options. But definetely not as GNU C lib does it; reordering, optional arguments, i speak against both of these two. Having said that, II., personally i use my own getopt implementation, which does it differently. "check-and-exit;e;" N_("note mail presence (of -L) via exit status"), And then there are things like git (iirc) and also certain OpenBSD infrastructure servers (ditto) which i think directly call functions or parse integers out into storage, i think busybox also has something similar, you know, ... waaayy more sophisticated; one could argue that moving as much computation as possible into a generic getopt is a real safety measure... |
|
|
romanzilka> If implemented, the function getopt_long() should be simultaneously incorporated into unistd.h (not getopt.h, as seen in glibc). I don't think that makes much sense, all existing code is using getopt.h for the various implementations of getopt_long(). romanzilka> The functionality of getopt_long_only() is equally desirable, but I suggest transforming it into a feature of getopt_long(), if possible. A feature which doesn't change the behavior of getopt_long() from the prespective of existing programs (expanding the expressiveness of has_arg in struct option, perhaps). Not really sure why you'd want to merge the two, the wording can split behavior between the two when needed, and implementations are free to have one being a wrapper of another, or both getopt_long() and getopt_long_only() being wrappers of common internal code. steffen> But definetely not as GNU C lib does it; reordering, optional arguments, i speak against both of these two. Reordering typically ends up disabled with POSIXLY_CORRECT anyway, which is the one that would make sense to standardize in POSIX. As for optional argument support, after poking at it (on musl and glibc), I think it's fine when specific to a long option as the equal sign form (ie. --foo=bar) is required to pass an option-argument. While optional-arguments for short-options are an ambiguous mess. (Somehow only one I've seen documenting that equal-sign restriction is IBM z/OS, but maybe I've missed it in the other manpages) Manpages for other systems as well: - https://man.openbsd.org/getopt_long - https://man.freebsd.org/cgi/man.cgi?getopt_long - https://man.dragonflybsd.org/?command=getopt_long§ion=ANY - https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getopt_long.3.html - https://illumos.org/man/3C/getopt_long - https://www.ibm.com/docs/en/zos/3.2.0?topic=functions-getopt-long-command-long-option-parsing (somehow IBM z/OS has it, apparently not IBM AIX) |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-12-01 23:00 | romanzilka | New Issue | |
| 2026-12-02 00:45 | steffen | Note Added: 0007573 | |
| 2026-12-02 02:29 | lanodan | Note Added: 0007574 | |
| 2026-12-02 02:30 | lanodan | Note Edited: 0007574 |