aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-07-04 20:51:29 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-07-04 20:51:29 +0200
commitd4e47fdb640c3ddce285157eee88db899461fa3a (patch)
treeec11a0df88f6db64a6017db7bc7efcaefedd04ec /src/string.c
parentstorage: requeue old runs from storage on startup (diff)
downloadcimple-d4e47fdb640c3ddce285157eee88db899461fa3a.tar.gz
cimple-d4e47fdb640c3ddce285157eee88db899461fa3a.zip
storage: mark completed runs as such
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c24
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;
+}