summaryrefslogtreecommitdiffstats
path: root/lib/strutils.c
diff options
context:
space:
mode:
authorSami Kerola2015-02-22 15:41:37 +0100
committerKarel Zak2015-02-24 11:33:31 +0100
commite5cf14765502931f7a89c95feee712e27f9003cc (patch)
treeb1ac1fddeb5091b5d6790ca4f09c9ad23812df97 /lib/strutils.c
parenttunelp: remove unnecessary preprocessor directives (diff)
downloadkernel-qcow2-util-linux-e5cf14765502931f7a89c95feee712e27f9003cc.tar.gz
kernel-qcow2-util-linux-e5cf14765502931f7a89c95feee712e27f9003cc.tar.xz
kernel-qcow2-util-linux-e5cf14765502931f7a89c95feee712e27f9003cc.zip
lib/strutils: move parse_switch() from setterm(1) to library
To allow sharing the code with other utilities. Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/strutils.c')
-rw-r--r--lib/strutils.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/strutils.c b/lib/strutils.c
index c4f9600b0..f6154aaa4 100644
--- a/lib/strutils.c
+++ b/lib/strutils.c
@@ -181,6 +181,14 @@ int isdigit_string(const char *str)
return p && p > str && !*p;
}
+int parse_switch(const char *arg, const char *a, const char *b)
+{
+ if (strcmp(arg, a) == 0)
+ return 1;
+ else if (strcmp(arg, b) == 0)
+ return 0;
+ errx(STRTOXX_EXIT_CODE, _("argument error: %s"), arg);
+}
#ifndef HAVE_MEMPCPY
void *mempcpy(void *restrict dest, const void *restrict src, size_t n)