diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-04 20:51:29 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-04 20:51:29 +0200 |
commit | d4e47fdb640c3ddce285157eee88db899461fa3a (patch) | |
tree | ec11a0df88f6db64a6017db7bc7efcaefedd04ec /src/string.c | |
parent | storage: requeue old runs from storage on startup (diff) | |
download | cimple-d4e47fdb640c3ddce285157eee88db899461fa3a.tar.gz cimple-d4e47fdb640c3ddce285157eee88db899461fa3a.zip |
storage: mark completed runs as such
Diffstat (limited to 'src/string.c')
-rw-r--r-- | src/string.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/string.c b/src/string.c index 878efeb..3a52ab2 100644 --- a/src/string.c +++ b/src/string.c @@ -6,7 +6,10 @@ */ #include "string.h" +#include "log.h" +#include <errno.h> +#include <stdlib.h> #include <string.h> char *stpecpy(char *dst, char *end, const char *src) @@ -23,3 +26,24 @@ char *stpecpy(char *dst, char *end, const char *src) end[-1] = '\0'; return end; } + +int string_to_int(const char *src, int *result) +{ + char *endptr = NULL; + + errno = 0; + long ret = strtol(src, &endptr, 10); + + if (errno) { + log_errno("strtol"); + return -1; + } + + if (endptr == src || *endptr != '\0') { + log_err("Invalid number: %s\n", src); + return -1; + } + + *result = (int)ret; + return 0; +} |