aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--LICENSE2
-rw-r--r--Makefile17
-rw-r--r--libsimple.h1
-rw-r--r--libsimple/strtoint.h362
-rw-r--r--strtoh.c30
-rw-r--r--strtohh.c30
-rw-r--r--strtoi.c30
-rw-r--r--strtoi16.c33
-rw-r--r--strtoi32.c33
-rw-r--r--strtoi64.c33
-rw-r--r--strtoi8.c33
-rw-r--r--strtou.c27
-rw-r--r--strtou16.c29
-rw-r--r--strtou32.c29
-rw-r--r--strtou64.c31
-rw-r--r--strtou8.c29
-rw-r--r--strtouh.c27
-rw-r--r--strtouhh.c27
-rw-r--r--strtouz.c18
-rw-r--r--strtoz.c18
20 files changed, 838 insertions, 1 deletions
diff --git a/LICENSE b/LICENSE
index c96ce73..f4e0c18 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
ISC License
-© 2017, 2018 Mattias Andrée <maandree@kth.se>
+© 2017, 2018, 2021, 2022 Mattias Andrée <maandree@kth.se>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
diff --git a/Makefile b/Makefile
index cc1c5c9..cc583ab 100644
--- a/Makefile
+++ b/Makefile
@@ -36,6 +36,7 @@ SUBHDR =\
libsimple/strdup.h\
libsimple/strn.h\
libsimple/strndup.h\
+ libsimple/strtoint.h\
libsimple/time.h\
libsimple/valloc.h\
libsimple/vallocz.h\
@@ -192,8 +193,24 @@ OBJ =\
strrnstr.o\
strrstr.o\
strstarts.o\
+ strtoh.o\
+ strtohh.o\
+ strtoi.o\
+ strtoi16.o\
+ strtoi32.o\
+ strtoi64.o\
+ strtoi8.o\
strtotimespec.o\
strtotimeval.o\
+ strtou.o\
+ strtou16.o\
+ strtou32.o\
+ strtou64.o\
+ strtou8.o\
+ strtouh.o\
+ strtouhh.o\
+ strtouz.o\
+ strtoz.o\
sumtimespec.o\
sumtimeval.o\
timespec2timeval.o\
diff --git a/libsimple.h b/libsimple.h
index e97ac27..6443dd4 100644
--- a/libsimple.h
+++ b/libsimple.h
@@ -128,6 +128,7 @@
#include "libsimple/array.h"
#include "libsimple/str.h"
#include "libsimple/strn.h"
+#include "libsimple/strtoint.h"
/**
diff --git a/libsimple/strtoint.h b/libsimple/strtoint.h
new file mode 100644
index 0000000..34c2432
--- /dev/null
+++ b/libsimple/strtoint.h
@@ -0,0 +1,362 @@
+/* See LICENSE file for copyright and license details. */
+
+
+/**
+ * Converts a string to a `signed char`
+ * according to the rules of strtol(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+signed char libsimple_strtohh(const char *restrict, char **restrict, int);
+#ifndef strtohh
+# define strtohh libsimple_strtohh
+#endif
+
+/**
+ * Converts a string to a `unsigned char`
+ * according to the rules of strtoul(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+unsigned char libsimple_strtouhh(const char *restrict, char **restrict, int);
+#ifndef strtouhh
+# define strtouhh libsimple_strtouhh
+#endif
+
+/**
+ * Converts a string to a `signed short int`
+ * according to the rules of strtol(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+signed short int libsimple_strtoh(const char *restrict, char **restrict, int);
+#ifndef strtoh
+# define strtoh libsimple_strtoh
+#endif
+
+/**
+ * Converts a string to a `unsigned short int`
+ * according to the rules of strtoul(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+unsigned short int libsimple_strtouh(const char *restrict, char **restrict, int);
+#ifndef strtouh
+# define strtouh libsimple_strtouh
+#endif
+
+/**
+ * Converts a string to a `signed int`
+ * according to the rules of strtol(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+signed int libsimple_strtoi(const char *restrict, char **restrict, int);
+#ifndef strtoi
+# define strtoi libsimple_strtoi
+#endif
+
+/**
+ * Converts a string to a `unsigned int`
+ * according to the rules of strtoul(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+unsigned int libsimple_strtou(const char *restrict, char **restrict, int);
+#ifndef strtou
+# define strtou libsimple_strtou
+#endif
+
+/**
+ * Converts a string to a `ssize_t`
+ * according to the rules of strtol(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+inline ssize_t
+libsimple_strtoz(const char *restrict nptr, char **restrict endptr, int base)
+{
+ return (ssize_t)strtol(nptr, endptr, base);
+}
+#ifndef strtoz
+# define strtoz libsimple_strtoz
+#endif
+
+/**
+ * Converts a string to a `size_t`
+ * according to the rules of strtol(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+inline size_t
+libsimple_strtouz(const char *restrict nptr, char **restrict endptr, int base)
+{
+ return (size_t)strtoul(nptr, endptr, base);
+}
+#ifndef strtouz
+# define strtouz libsimple_strtouz
+#endif
+
+/**
+ * Converts a string to a `int8_t`
+ * according to the rules of strtol(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+int_least8_t libsimple_strtoi8(const char *restrict, char **restrict, int);
+#ifndef strtoi8
+# define strtoi8 libsimple_strtoi8
+#endif
+
+/**
+ * Converts a string to a `uint8_t`
+ * according to the rules of strtoul(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+uint_least8_t libsimple_strtou8(const char *restrict, char **restrict, int);
+#ifndef strtou8
+# define strtou8 libsimple_strtou8
+#endif
+
+/**
+ * Converts a string to a `int16_t`
+ * according to the rules of strtol(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+int_least16_t libsimple_strtoi16(const char *restrict, char **restrict, int);
+#ifndef strtoi16
+# define strtoi16 libsimple_strtoi16
+#endif
+
+/**
+ * Converts a string to a `uint16_t`
+ * according to the rules of strtoul(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+uint_least16_t libsimple_strtou16(const char *restrict, char **restrict, int);
+#ifndef strtou16
+# define strtou16 libsimple_strtou16
+#endif
+
+/**
+ * Converts a string to a `int32_t`
+ * according to the rules of strtol(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+int_least32_t libsimple_strtoi32(const char *restrict, char **restrict, int);
+#ifndef strtoi32
+# define strtoi32 libsimple_strtoi32
+#endif
+
+/**
+ * Converts a string to a `uint32_t`
+ * according to the rules of strtoul(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+uint_least32_t libsimple_strtou32(const char *restrict, char **restrict, int);
+#ifndef strtou32
+# define strtou32 libsimple_strtou32
+#endif
+
+/**
+ * Converts a string to a `int64_t`
+ * according to the rules of strtol(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+int_least64_t libsimple_strtoi64(const char *restrict, char **restrict, int);
+#ifndef strtoi64
+# define strtoi64 libsimple_strtoi64
+#endif
+
+/**
+ * Converts a string to a `uint64_t`
+ * according to the rules of strtoul(3)
+ *
+ * @param nptr The string to parse
+ * @param endptr Output parameter for the position in `nptr`
+ * where the first character that is not part
+ * of the interpreted value resides
+ * @param base The base the value is encoded in, 0 if
+ * the function shall accept a prefix to
+ * specify the base if it is not 10
+ * @return The encoded value (`errno` is unchanges), or
+ * if out of range (`errno` set to `ERANGE`), the
+ * closed value that can be represented; 0 on
+ * failure (unless `errno` not set to `ERANGE`)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__(2), __warn_unused_result__)))
+uint_least64_t libsimple_strtou64(const char *restrict, char **restrict, int);
+#ifndef strtou64
+# define strtou64 libsimple_strtou64
+#endif
diff --git a/strtoh.c b/strtoh.c
new file mode 100644
index 0000000..47ea6d3
--- /dev/null
+++ b/strtoh.c
@@ -0,0 +1,30 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+
+signed short int
+libsimple_strtoh(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */
+{
+ signed long int r = strtol(nptr, end, base);
+ if(r < SHRT_MIN) {
+ r = SHRT_MIN;
+ errno = ERANGE;
+ } else if(r > SHRT_MAX) {
+ r = SHRT_MAX;
+ errno = ERANGE;
+ }
+ return (signed short int)r;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
diff --git a/strtohh.c b/strtohh.c
new file mode 100644
index 0000000..67da198
--- /dev/null
+++ b/strtohh.c
@@ -0,0 +1,30 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+
+signed char
+libsimple_strtohh(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */
+{
+ signed long int r = strtol(nptr, end, base);
+ if(r < SCHAR_MIN) {
+ r = SCHAR_MIN;
+ errno = ERANGE;
+ } else if(r > SCHAR_MAX) {
+ r = SCHAR_MAX;
+ errno = ERANGE;
+ }
+ return (signed char)r;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
diff --git a/strtoi.c b/strtoi.c
new file mode 100644
index 0000000..6b3fcb2
--- /dev/null
+++ b/strtoi.c
@@ -0,0 +1,30 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+
+signed int
+libsimple_strtoi(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */
+{
+ signed int r = strtol(nptr, end, base);
+ if(r < INT_MIN) {
+ r = INT_MIN;
+ errno = ERANGE;
+ } else if(r > INT_MAX) {
+ r = INT_MAX;
+ errno = ERANGE;
+ }
+ return (signed int)r;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
diff --git a/strtoi16.c b/strtoi16.c
new file mode 100644
index 0000000..2960603
--- /dev/null
+++ b/strtoi16.c
@@ -0,0 +1,33 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+#define RET_MAX 32767LL
+#define RET_MIN (-RET_MAX - 1LL)
+
+
+int_least16_t
+libsimple_strtoi16(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_least16_t)r;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
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
diff --git a/strtoi64.c b/strtoi64.c
new file mode 100644
index 0000000..963574b
--- /dev/null
+++ b/strtoi64.c
@@ -0,0 +1,33 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+#define RET_MAX 9223372036854775807LL
+#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
diff --git a/strtoi8.c b/strtoi8.c
new file mode 100644
index 0000000..f6fecc6
--- /dev/null
+++ b/strtoi8.c
@@ -0,0 +1,33 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+#define RET_MAX 127LL
+#define RET_MIN (-RET_MAX - 1LL)
+
+
+int_least8_t
+libsimple_strtoi8(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_least8_t)r;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
diff --git a/strtou.c b/strtou.c
new file mode 100644
index 0000000..4201c1f
--- /dev/null
+++ b/strtou.c
@@ -0,0 +1,27 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+
+unsigned int
+libsimple_strtou(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */
+{
+ signed long int r = strtoul(nptr, end, base);
+ if(r > UINT_MAX) {
+ r = UINT_MAX;
+ errno = ERANGE;
+ }
+ return (unsigned int)r;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
diff --git a/strtou16.c b/strtou16.c
new file mode 100644
index 0000000..dea2678
--- /dev/null
+++ b/strtou16.c
@@ -0,0 +1,29 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+#define RET_MAX 65535ULL
+
+
+uint_least16_t
+libsimple_strtou16(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */
+{
+ uintmax_t r = strtoumax(nptr, end, base);
+ if(r > RET_MAX) {
+ r = RET_MAX;
+ errno = ERANGE;
+ }
+ return (uint_least16_t)r;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
diff --git a/strtou32.c b/strtou32.c
new file mode 100644
index 0000000..0260d4f
--- /dev/null
+++ b/strtou32.c
@@ -0,0 +1,29 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+#define RET_MAX 4294967295ULL
+
+
+uint_least32_t
+libsimple_strtou32(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */
+{
+ uintmax_t r = strtoumax(nptr, end, base);
+ if(r > RET_MAX) {
+ r = RET_MAX;
+ errno = ERANGE;
+ }
+ return (uint_least32_t)r;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
diff --git a/strtou64.c b/strtou64.c
new file mode 100644
index 0000000..1deb3a5
--- /dev/null
+++ b/strtou64.c
@@ -0,0 +1,31 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+#define RET_MAX 18446744073709551615ULL
+
+
+uint_least64_t
+libsimple_strtou64(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */
+{
+ uintmax_t r = strtoumax(nptr, end, base);
+#if UINTMAX_MAX > RET_MAX
+ if(r > RET_MAX) {
+ r = RET_MAX;
+ errno = ERANGE;
+ }
+#endif
+ return (uint_least64_t)r;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
diff --git a/strtou8.c b/strtou8.c
new file mode 100644
index 0000000..5a8bcf5
--- /dev/null
+++ b/strtou8.c
@@ -0,0 +1,29 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+#define RET_MAX 255ULL
+
+
+uint_least8_t
+libsimple_strtou8(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */
+{
+ uintmax_t r = strtoumax(nptr, end, base);
+ if(r > RET_MAX) {
+ r = RET_MAX;
+ errno = ERANGE;
+ }
+ return (uint_least8_t)r;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
diff --git a/strtouh.c b/strtouh.c
new file mode 100644
index 0000000..7e4505f
--- /dev/null
+++ b/strtouh.c
@@ -0,0 +1,27 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+
+unsigned short int
+libsimple_strtouh(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */
+{
+ signed long int r = strtoul(nptr, end, base);
+ if(r > USHRT_MAX) {
+ r = USHRT_MAX;
+ errno = ERANGE;
+ }
+ return (unsigned short int)r;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
diff --git a/strtouhh.c b/strtouhh.c
new file mode 100644
index 0000000..b13800d
--- /dev/null
+++ b/strtouhh.c
@@ -0,0 +1,27 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+
+unsigned char
+libsimple_strtouhh(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */
+{
+ signed long int r = strtoul(nptr, end, base);
+ if(r > UCHAR_MAX) {
+ r = UCHAR_MAX;
+ errno = ERANGE;
+ }
+ return (unsigned char)r;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
diff --git a/strtouz.c b/strtouz.c
new file mode 100644
index 0000000..2885600
--- /dev/null
+++ b/strtouz.c
@@ -0,0 +1,18 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+
+extern inline size_t libsimple_strtouz(const char *restrict nptr, char **restrict end, int base); /* TODO test, man */
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif
diff --git a/strtoz.c b/strtoz.c
new file mode 100644
index 0000000..dbaccad
--- /dev/null
+++ b/strtoz.c
@@ -0,0 +1,18 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+
+extern inline ssize_t libsimple_strtoz(const char *restrict nptr, char **restrict end, int base); /* TODO test, man */
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ return 0;
+}
+
+#endif