diff options
author | Karel Zak | 2017-01-28 12:39:30 +0100 |
---|---|---|
committer | Karel Zak | 2017-01-28 12:39:30 +0100 |
commit | 61cbc8a3f5aa1b4acb4e5a6b7b251b8c5b8f05b5 (patch) | |
tree | c0d1ce4f8391dd496d760417c1174e7d27ac2100 | |
parent | libfdisk: (gpt) add check for entries array size (diff) | |
download | kernel-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.h | 8 | ||||
-rw-r--r-- | lib/strutils.c | 9 |
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; } |