From: Karel Zak Date: Tue, 29 Nov 2011 17:21:49 +0000 (+0100) Subject: include,optutils: add option_to_longopt() X-Git-Tag: v2.21-rc1~151 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=732a631126a00ee52b9582e8adb7cc64bbcbaec0;p=thirdparty%2Futil-linux.git include,optutils: add option_to_longopt() Signed-off-by: Karel Zak --- diff --git a/include/optutils.h b/include/optutils.h new file mode 100644 index 0000000000..f66d669c86 --- /dev/null +++ b/include/optutils.h @@ -0,0 +1,15 @@ +#ifndef UTIL_LINUX_OPTUTILS_H +#define UTIL_LINUX_OPTUTILS_H + +static inline const char *option_to_longopt(int c, const struct option *opts) +{ + const struct option *o; + + for (o = opts; o->name; o++) + if (o->val == c) + return o->name; + return NULL; +} + +#endif + diff --git a/libmount/samples/mount.c b/libmount/samples/mount.c index bb7ee9e542..2e58eedb3f 100644 --- a/libmount/samples/mount.c +++ b/libmount/samples/mount.c @@ -32,6 +32,7 @@ #include "nls.h" #include "c.h" #include "env.h" +#include "optutils.h" /*** TODO: DOCS: * @@ -75,7 +76,7 @@ static void __attribute__((__noreturn__)) print_version(void) mnt_get_library_version(&ver); - printf("%s from %s (libmount %s)\n", + printf(_("%s from %s (libmount %s)\n"), program_invocation_short_name, PACKAGE_STRING, ver); exit(EX_SUCCESS); } @@ -89,16 +90,6 @@ static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__) return 0; } -static const char *opt_to_longopt(int c, const struct option *opts) -{ - const struct option *o; - - for (o = opts; o->name; o++) - if (o->val == c) - return o->name; - return NULL; -} - static void print_all(struct libmnt_context *cxt, char *pattern, int show_label) { struct libmnt_table *tb; @@ -328,7 +319,7 @@ int main(int argc, char **argv) /* only few options are allowed for non-root users */ if (mnt_context_is_restricted(cxt) && !strchr("hlLUVv", c)) - exit_non_root(opt_to_longopt(c, longopts)); + exit_non_root(option_to_longopt(c, longopts)); switch(c) { case 'a':