GNU libc's getopt_long(3) have the tradition of not shuffling arguments
to find options when either POSIXLY_CORRECT is defined in environment
variables or '+' prepended in short options. Hence, the current code
base is fine as is fine as is for util-linux built with GNU libc.
However, musl libc only honour POSIX convention when short options
prepended with '+'. musl libc doesn't care about POSIXLY_CORRECT.
Thus, the behaviour of util-linux's getopt(1) that linked with musl-libc
doesn't match with its own documentation.
Let's make sure a '+' is always prepended to short options if
POSIXLY_CORRECT is defined.
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
changed in include/c.h and applied via sed:
sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Consolidate --help and --version descriptions. We are
now able to align them to the other options.
We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
... and use errtryhelp() instead of usage().
Note in past "getopt --help" returned 2. But it is otherwise
documented and was just a mistake IMO. See the unreachable exit(0)
which was removed here: d1d03b54
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
The getopt(1) is short living command, and one could argue ensuring all
allocations are freed at end of execution is waste of time. There is a
point in that, but making test-suite runs to be less noisy with ASAN is also
nice as it encourages reading the errors when/if they happen.
Reviewed-by: Yuriy M. Kaminskiy <yumkam@gmail.com>
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
BSD gets the program name for warnings from getprogname() and not
from argv. Thus we use setprogname() there.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
This adds a concise description of a tool to its usage text.
A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
This normalizes the help text of getopt, clarifies one description,
and also adjust two comments.
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
Terminating the ctl->long_options list once when adding options is
completed is enough. This also allows moving ctl->long_options_nr
increment to more appropriate location.
CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Avoid passing getopt_control stucture in when returning a value is enough.
CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
A change towards less indirection, and a change to free allocated memory.
CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Functions are in right order so they do not need prototypes, with effect
of not needing to keep function argument changes in sync in two locations.
CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
From manual page: 'If the first character of optstring is '-', then each
nonoption argv-element is handled as if it were the argument of an option
with character code 1.'
Reference: http://man7.org/linux/man-pages/man3/getopt.3.html
CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Translating these text elements should happen only once, which is
more likely when the text macros are used properly.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>