From 5d2bbca39c79dcc73060ac480a4e229affef0a14 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 10 Jun 2022 19:34:11 +0200 Subject: Add strto[u]{hh,h,z}, strto{i,u}{,8,16,32,64} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- strtoi32.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 strtoi32.c (limited to 'strtoi32.c') diff --git a/strtoi32.c b/strtoi32.c new file mode 100644 index 0000000..ce4a7f4 --- /dev/null +++ b/strtoi32.c @@ -0,0 +1,33 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + +#define RET_MAX 2147483647LL +#define RET_MIN (-RET_MAX - 1LL) + + +int_least32_t +libsimple_strtoi32(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */ +{ + intmax_t r = strtoimax(nptr, end, base); + if(r < RET_MIN) { + r = RET_MIN; + errno = ERANGE; + } else if(r > RET_MAX) { + r = RET_MAX; + errno = ERANGE; + } + return (int_least32_t)r; +} + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif -- cgit v1.2.3-70-g09d2