From 78bf2fe4a5bf37514f6dfd203ef969da0bf40c2e Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Mon, 22 Sep 2025 17:32:44 +0200 Subject: Setup project skeleton --- getul_n.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 getul_n.c (limited to 'getul_n.c') diff --git a/getul_n.c b/getul_n.c new file mode 100644 index 0000000..cf150c9 --- /dev/null +++ b/getul_n.c @@ -0,0 +1,33 @@ +#define _POSIX_C_SOURCE 200809L + +#include "utils.h" +#include +#include +#include +#include +#include + +int getul_n(const char *const s, unsigned long *const out) +{ + char *end; + unsigned long v; + + errno = 0; + v = strtoull(s, &end, 10); + + if (errno) + { + fprintf(stderr, "%s: strtoul(3) %s: %s\n", __func__, s, + strerror(errno)); + return -1; + } + else if (*end || v > LONG_MAX) + { + fprintf(stderr, "%s: invalid number: %.*s\n", __func__, + (int)(end - s), s); + return -1; + } + + *out = v; + return 0; +} -- cgit v1.2.3