libutil

C Utility Library
git clone http://git.omkov.net/libutil
Log | Tree | Refs | README | LICENCE | Download

AuthorJamozed <[email protected]>
Date2022-02-04 06:57:13
Commit1aa1d3fdacc0361e4bf1fab446e075ab27f3cc2a
Parentce5f15cdf9e3ce262c7a01e0db791a6384f93432

strconv: Replace stdint types with libutil ones

Diffstat

M src/strconv.h | 20 ++++++++++----------
R src/strtoi.c -> src/strtos.c | 37 +++++++++++++++++++------------------
M src/strtou.c | 37 +++++++++++++++++++------------------

3 files changed, 48 insertions, 46 deletions

diff --git a/src/strconv.h b/src/strconv.h
index 655ef06..5901fcb 100644
--- a/src/strconv.h
+++ b/src/strconv.h
@@ -1,4 +1,4 @@
-// util/strconv.h, version 1.1.1
+// util/strconv.h, version 1.1.2
 // String conversion header file from libutil
 // Copyright (C) 2021, Jakob Wakeling
 // All rights reserved.
@@ -33,16 +33,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 #ifndef UTIL_STRCONV_H_3EQMSZZK
 #define UTIL_STRCONV_H_3EQMSZZK
 
-#include <stdint.h>
+#include "util.h"
 
-int8_t strtoi8(const char *nptr, char **endptr, register int base);
-int16_t strtoi16(const char *nptr, char **endptr, register int base);
-int32_t strtoi32(const char *nptr, char **endptr, register int base);
-int64_t strtoi64(const char *nptr, char **endptr, register int base);
+s8 strtos8(const char *nptr, char **endptr, register int base);
+s16 strtos16(const char *nptr, char **endptr, register int base);
+s32 strtos32(const char *nptr, char **endptr, register int base);
+s64 strtos64(const char *nptr, char **endptr, register int base);
 
-uint8_t strtou8(const char *nptr, char **endptr, register int base);
-uint16_t strtou16(const char *nptr, char **endptr, register int base);
-uint32_t strtou32(const char *nptr, char **endptr, register int base);
-uint64_t strtou64(const char *nptr, char **endptr, register int base);
+u8 strtou8(const char *nptr, char **endptr, register int base);
+u16 strtou16(const char *nptr, char **endptr, register int base);
+u32 strtou32(const char *nptr, char **endptr, register int base);
+u64 strtou64(const char *nptr, char **endptr, register int base);
 
 #endif // UTIL_STRCONV_H_3EQMSZZK
diff --git a/src/strtoi.c b/src/strtos.c
similarity index 80%
rename from src/strtoi.c
rename to src/strtos.c
index b3d94dc..c09c2e3 100644
--- a/src/strtoi.c
+++ b/src/strtos.c
@@ -1,4 +1,4 @@
-// util/strtoi.c, version 1.1.1
+// util/strtos.c, version 1.1.2
 // String conversion source file from libutil
 // Copyright (C) 2021, Jakob Wakeling
 // All rights reserved.
@@ -30,14 +30,15 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 */
 
+#include "util.h"
+
 #include <ctype.h>
 #include <errno.h>
 #include <stdbool.h>
-#include <stdint.h>
 
 /* Convert a string to a signed 8-bit integer */
-int8_t strtoi8(const char *nptr, char **endptr, register int base) {
-	register const char *s = nptr; register uint8_t i = 0, c; bool neg = false;
+s8 strtos8(const char *nptr, char **endptr, register int base) {
+	register const char *s = nptr; register u8 i = 0, c; bool neg = false;
 
 	for (; isspace(*s); ++s);
 
@@ -56,8 +57,8 @@ int8_t strtoi8(const char *nptr, char **endptr, register int base) {
 		else { break; }
 
 		if (c >= base) { break; }
-		if (i > (neg ? -INT8_MIN : INT8_MAX - c) / base) {
-			errno = ERANGE; i = neg ? INT8_MIN : INT8_MAX; goto end;
+		if (i > (neg ? -(S8_MIN + 1) : S8_MAX - c) / base) {
+			errno = ERANGE; i = neg ? S8_MIN : S8_MAX; goto end;
 		}
 
 		i = i * base + c;
@@ -68,8 +69,8 @@ end:;
 }
 
 /* Convert a string to a signed 16-bit integer */
-int16_t strtoi16(const char *nptr, char **endptr, register int base) {
-	register const char *s = nptr; register uint16_t i = 0, c; bool neg = false;
+s16 strtos16(const char *nptr, char **endptr, register int base) {
+	register const char *s = nptr; register u16 i = 0, c; bool neg = false;
 
 	for (; isspace(*s); ++s);
 
@@ -88,8 +89,8 @@ int16_t strtoi16(const char *nptr, char **endptr, register int base) {
 		else { break; }
 
 		if (c >= base) { break; }
-		if (i > (neg ? -INT16_MIN : INT16_MAX - c) / base) {
-			errno = ERANGE; i = neg ? INT16_MIN : INT16_MAX; goto end;
+		if (i > (neg ? -(S16_MIN + 1) : S16_MAX - c) / base) {
+			errno = ERANGE; i = neg ? S16_MIN : S16_MAX; goto end;
 		}
 
 		i = i * base + c;
@@ -100,8 +101,8 @@ end:;
 }
 
 /* Convert a string to a signed 32-bit integer */
-int32_t strtoi32(const char *nptr, char **endptr, register int base) {
-	register const char *s = nptr; register uint32_t i = 0, c; bool neg = false;
+s32 strtos32(const char *nptr, char **endptr, register int base) {
+	register const char *s = nptr; register u32 i = 0, c; bool neg = false;
 
 	for (; isspace(*s); ++s);
 
@@ -120,8 +121,8 @@ int32_t strtoi32(const char *nptr, char **endptr, register int base) {
 		else { break; }
 
 		if (c >= base) { break; }
-		if (i > (neg ? -INT32_MIN : INT32_MAX - c) / base) {
-			errno = ERANGE; i = neg ? INT32_MIN : INT32_MAX; goto end;
+		if (i > (neg ? -(S32_MIN + 1) : S32_MAX - c) / base) {
+			errno = ERANGE; i = neg ? S32_MIN : S32_MAX; goto end;
 		}
 
 		i = i * base + c;
@@ -132,8 +133,8 @@ end:;
 }
 
 /* Convert a string to a signed 64-bit integer */
-int64_t strtoi64(const char *nptr, char **endptr, register int base) {
-	register const char *s = nptr; register uint64_t i = 0, c; bool neg = false;
+s64 strtos64(const char *nptr, char **endptr, register int base) {
+	register const char *s = nptr; register u64 i = 0, c; bool neg = false;
 
 	for (; isspace(*s); ++s);
 
@@ -152,8 +153,8 @@ int64_t strtoi64(const char *nptr, char **endptr, register int base) {
 		else { break; }
 
 		if (c >= base) { break; }
-		if (i > (neg ? -INT64_MIN : INT64_MAX - c) / base) {
-			errno = ERANGE; i = neg ? INT64_MIN : INT64_MAX; goto end;
+		if (i > (neg ? -(S64_MIN + 1) : S64_MAX - c) / base) {
+			errno = ERANGE; i = neg ? S64_MIN : S64_MAX; goto end;
 		}
 
 		i = i * base + c;
diff --git a/src/strtou.c b/src/strtou.c
index 7e9acf0..e865866 100644
--- a/src/strtou.c
+++ b/src/strtou.c
@@ -1,4 +1,4 @@
-// util/strtou.c, version 1.1.1
+// util/strtou.c, version 1.1.2
 // String conversion source file from libutil
 // Copyright (C) 2021, Jakob Wakeling
 // All rights reserved.
@@ -30,13 +30,14 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 */
 
+#include "util.h"
+
 #include <ctype.h>
 #include <errno.h>
-#include <stdint.h>
 
 /* Convert a string to an unsigned 8-bit integer */
-uint8_t strtou8(const char *nptr, char **endptr, register int base) {
-	register const char *s = nptr; register uint8_t i = 0, c;
+u8 strtou8(const char *nptr, char **endptr, register int base) {
+	register const char *s = nptr; register u8 i = 0, c;
 
 	for (; isspace(*s); ++s);
 
@@ -55,8 +56,8 @@ uint8_t strtou8(const char *nptr, char **endptr, register int base) {
 		else { break; }
 
 		if (c >= base) { break; }
-		if (i > (UINT8_MAX - c) / base) {
-			errno = ERANGE; i = UINT8_MAX; goto end;
+		if (i > (U8_MAX - c) / base) {
+			errno = ERANGE; i = U8_MAX; goto end;
 		}
 
 		i = i * base + c;
@@ -67,8 +68,8 @@ end:;
 }
 
 /* Convert a string to an unsigned 16-bit integer */
-uint16_t strtou16(const char *nptr, char **endptr, register int base) {
-	register const char *s = nptr; register uint16_t i = 0, c;
+u16 strtou16(const char *nptr, char **endptr, register int base) {
+	register const char *s = nptr; register u16 i = 0, c;
 
 	for (; isspace(*s); ++s);
 
@@ -87,8 +88,8 @@ uint16_t strtou16(const char *nptr, char **endptr, register int base) {
 		else { break; }
 
 		if (c >= base) { break; }
-		if (i > (UINT16_MAX - c) / base) {
-			errno = ERANGE; i = UINT16_MAX; goto end;
+		if (i > (U16_MAX - c) / base) {
+			errno = ERANGE; i = U16_MAX; goto end;
 		}
 
 		i = i * base + c;
@@ -99,8 +100,8 @@ end:;
 }
 
 /* Convert a string to an unsigned 32-bit integer */
-uint32_t strtou32(const char *nptr, char **endptr, register int base) {
-	register const char *s = nptr; register uint32_t i = 0, c;
+u32 strtou32(const char *nptr, char **endptr, register int base) {
+	register const char *s = nptr; register u32 i = 0, c;
 
 	for (; isspace(*s); ++s);
 
@@ -119,8 +120,8 @@ uint32_t strtou32(const char *nptr, char **endptr, register int base) {
 		else { break; }
 
 		if (c >= base) { break; }
-		if (i > (UINT32_MAX - c) / base) {
-			errno = ERANGE; i = UINT32_MAX; goto end;
+		if (i > (U32_MAX - c) / base) {
+			errno = ERANGE; i = U32_MAX; goto end;
 		}
 
 		i = i * base + c;
@@ -131,8 +132,8 @@ end:;
 }
 
 /* Convert a string to an unsigned 64-bit integer */
-uint64_t strtou64(const char *nptr, char **endptr, register int base) {
-	register const char *s = nptr; register uint64_t i = 0, c;
+u64 strtou64(const char *nptr, char **endptr, register int base) {
+	register const char *s = nptr; register u64 i = 0, c;
 
 	for (; isspace(*s); ++s);
 
@@ -151,8 +152,8 @@ uint64_t strtou64(const char *nptr, char **endptr, register int base) {
 		else { break; }
 
 		if (c >= base) { break; }
-		if (i > (UINT64_MAX - c) / base) {
-			errno = ERANGE; i = UINT64_MAX; goto end;
+		if (i > (U64_MAX - c) / base) {
+			errno = ERANGE; i = U64_MAX; goto end;
 		}
 
 		i = i * base + c;