]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include,optutils: add option_to_longopt()
authorKarel Zak <kzak@redhat.com>
Tue, 29 Nov 2011 17:21:49 +0000 (18:21 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 29 Nov 2011 17:21:49 +0000 (18:21 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/optutils.h [new file with mode: 0644]
libmount/samples/mount.c

diff --git a/include/optutils.h b/include/optutils.h
new file mode 100644 (file)
index 0000000..f66d669
--- /dev/null
@@ -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
+
index bb7ee9e542d8238ea534b82b024892e1c9ac2cdb..2e58eedb3f0cc6a41b73e3bcca36542162e7673d 100644 (file)
@@ -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':