summaryrefslogtreecommitdiffstats
path: root/misc-utils/getopt.c
Commit message (Collapse)AuthorAgeFilesLines
* getopt: be sure that options array is terminatedKarel Zak2016-10-211-8/+11
| | | | | Reported-by: Anders Kaseorg <andersk@mit.edu> Signed-off-by: Karel Zak <kzak@redhat.com>
* include/closestream: define exit codesKarel Zak2016-08-161-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* getopt: keep pointer to 'name' in control structKarel Zak2016-04-221-10/+7Star
| | | | | | It's seems more readable than call free(argv[0]). Signed-off-by: Karel Zak <kzak@redhat.com>
* getopt: fix memory leaks and integer overflows [ASAN & valgrind]Sami Kerola2016-04-201-7/+18
| | | | | | | | | | | 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>
* getopt: make sure setprogname provided by non-Linux systemKarel Zak2016-04-041-1/+1
| | | | | | | based on suggestion from Ruediger Meier. Reported-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* getopt: fix -n name for BSDRuediger Meier2016-03-071-2/+9
| | | | | | | 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>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-0/+3
| | | | | | | | | 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>
* textual: do not start option descriptions with a capitalBenno Schulenberg2014-12-191-14/+14
| | | | | | | This normalizes the help text of getopt, clarifies one description, and also adjust two comments. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* getopt: cleanup add_log_options()Karel Zak2014-12-091-6/+9
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* getopt: rename function to keep code readableKarel Zak2014-12-091-6/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* getopt: fix compiler warningKarel Zak2014-12-091-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* getopt: avoid re-terminating long_option list at every updateSami Kerola2014-12-081-11/+10Star
| | | | | | | | | 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>
* getopt: change --shell argument parsing functionSami Kerola2014-12-081-12/+10Star
| | | | | | | 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>
* getopt: prefer switch-case rather than long if statementSami Kerola2014-12-081-27/+37
| | | | | | | And avoid testing same thing time after time. CC: Frodo Looijaard <frodo@frodo.looijaard.name> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* getopt: remove unnecessary codeSami Kerola2014-12-081-9/+1Star
| | | | | | | The control structure is initialized in main(). CC: Frodo Looijaard <frodo@frodo.looijaard.name> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* getopt: make normalize() print stringsSami Kerola2014-12-081-14/+12Star
| | | | | | | 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>
* getopt: use xstrdup rather than malloc + strcpySami Kerola2014-12-081-12/+5Star
| | | | | CC: Frodo Looijaard <frodo@frodo.looijaard.name> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* getopt: add struct getopt_control and remove global variablesSami Kerola2014-12-081-81/+83
| | | | | CC: Frodo Looijaard <frodo@frodo.looijaard.name> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* getopt: remove function prototypesSami Kerola2014-12-081-10/+0Star
| | | | | | | | 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>
* getopt: make nonoptions optstring comment correctSami Kerola2014-12-081-2/+2
| | | | | | | | | | 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>
* getopt: sync with 1.1.6 releaseSami Kerola2014-12-081-4/+17
| | | | | | Reference: http://www.spinics.net/lists/util-linux-ng/msg10556.html CC: Frodo Looijaard <frodo@frodo.looijaard.name> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: use usage() text element macrosSami Kerola2014-10-011-7/+5Star
| | | | | | | 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>
* textual: use manual tail usage() macroSami Kerola2014-10-011-0/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* getopt: fix usage() typo unquote -> unquotedKarel Zak2013-04-051-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* getopt: fix normalize() usage [coverity scan]Karel Zak2013-03-271-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: spell and encode the name of Arkadiusz Miƛkiewicz correctlyBenno Schulenberg2013-02-061-1/+1
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* textual: use UTIL_LINUX_VERSION everywhereKarel Zak2013-01-251-3/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* getopt: make the code more readable for analysersKarel Zak2012-09-071-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: move getopt to misc-utils/Karel Zak2012-06-261-0/+458
Signed-off-by: Karel Zak <kzak@redhat.com>