From 67a0755a248c9793a1e7a3cf73f4041b2103ebf7 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Mon, 2 Oct 2023 02:34:50 -0400 Subject: Add strict_strtoul Signed-off-by: Malfurious --- helpers.c | 6 ++++++ helpers.h | 1 + 2 files changed, 7 insertions(+) diff --git a/helpers.c b/helpers.c index 8e3be13..163cd2e 100644 --- a/helpers.c +++ b/helpers.c @@ -11,6 +11,12 @@ void *xmalloc(size_t size) { return ptr; } +unsigned long strict_strtoul(const char *nptr, int base) { + char *endptr; + unsigned long ret = strtoul(nptr, &endptr, base); + return (*endptr ? 0 : ret); +} + void cursinit(void) { setlocale(LC_ALL, ""); initscr(); diff --git a/helpers.h b/helpers.h index 02607bb..a415a6c 100644 --- a/helpers.h +++ b/helpers.h @@ -7,6 +7,7 @@ #define KEY_ESCAPE 0x1b extern void *xmalloc(size_t size); +extern unsigned long strict_strtoul(const char *nptr, int base); extern void cursinit(void); extern void cursupdate(void); -- cgit v1.2.3