summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2017-01-28 12:39:30 +0100
committerKarel Zak2017-01-28 12:39:30 +0100
commit61cbc8a3f5aa1b4acb4e5a6b7b251b8c5b8f05b5 (patch)
treec0d1ce4f8391dd496d760417c1174e7d27ac2100
parentlibfdisk: (gpt) add check for entries array size (diff)
downloadkernel-qcow2-util-linux-61cbc8a3f5aa1b4acb4e5a6b7b251b8c5b8f05b5.tar.gz
kernel-qcow2-util-linux-61cbc8a3f5aa1b4acb4e5a6b7b251b8c5b8f05b5.tar.xz
kernel-qcow2-util-linux-61cbc8a3f5aa1b4acb4e5a6b7b251b8c5b8f05b5.zip
lib/strutils: return end pointer by isdigit_string()
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--include/strutils.h8
-rw-r--r--lib/strutils.c9
2 files changed, 13 insertions, 4 deletions
diff --git a/include/strutils.h b/include/strutils.h
index aa31fc984..28c1b5e5d 100644
--- a/include/strutils.h
+++ b/include/strutils.h
@@ -39,8 +39,12 @@ extern unsigned long strtoul_or_err(const char *str, const char *errmesg);
extern void strtotimeval_or_err(const char *str, struct timeval *tv,
const char *errmesg);
-extern int isdigit_string(const char *str);
-extern int isxdigit_string(const char *str);
+extern int isdigit_strend(const char *str, const char **end);
+#define isdigit_string(_s) isdigit_strend(_s, NULL)
+
+extern int isxdigit_strend(const char *str, const char **end);
+#define isxdigit_string(_s) isxdigit_strend(_s, NULL)
+
extern int parse_switch(const char *arg, const char *errmesg, ...);
diff --git a/lib/strutils.c b/lib/strutils.c
index d3daa369d..74c850bce 100644
--- a/lib/strutils.c
+++ b/lib/strutils.c
@@ -174,21 +174,26 @@ int strtosize(const char *str, uintmax_t *res)
return parse_size(str, res, NULL);
}
-int isdigit_string(const char *str)
+int isdigit_strend(const char *str, const char **end)
{
const char *p;
for (p = str; p && *p && isdigit((unsigned char) *p); p++);
+ if (end)
+ *end = p;
return p && p > str && !*p;
}
-int isxdigit_string(const char *str)
+int isxdigit_strend(const char *str, const char **end)
{
const char *p;
for (p = str; p && *p && isxdigit((unsigned char) *p); p++);
+ if (end)
+ *end = p;
+
return p && p > str && !*p;
}