From 7d9b89e9f8a055bca216cccc7f8ec8760133fb80 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Mon, 20 Jun 2022 12:51:19 -0500 Subject: [PATCH] Tranform string values into 64-bit unsigned integers --- include/gargoyle/codex.h | 1 + src/scribe.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/gargoyle/codex.h b/include/gargoyle/codex.h index 0d09ba1..aa3edd6 100644 --- a/include/gargoyle/codex.h +++ b/include/gargoyle/codex.h @@ -12,5 +12,6 @@ static const uint8_t GARGOYLE_TYPE_DBLE = 1 << 4; static const uint8_t GARGOYLE_ERR_SUCCESS = 0; static const uint8_t GARGOYLE_ERR_UNKNOWN_OPT = 1; static const uint8_t GARGOYLE_ERR_VALUE_REQUIRED = 2; +static const uint8_t GARGOYLE_ERR_INVALID_UINT = 3; #endif diff --git a/src/scribe.c b/src/scribe.c index 4701faf..b46ee6c 100644 --- a/src/scribe.c +++ b/src/scribe.c @@ -1,6 +1,7 @@ #include #include #include +#include uint8_t gargoyle_from_bool(struct gargoyle_opt *opt, const char *brand) { if(opt->val) { @@ -12,5 +13,15 @@ uint8_t gargoyle_from_bool(struct gargoyle_opt *opt, const char *brand) { } uint8_t gargoyle_from_rope(struct gargoyle_opt *opt, const char *brand) { + if(opt->type & GARGOYLE_TYPE_UINT) { + char *end = NULL; + uint64_t *val = opt->val; + *val = strtoull(brand, &end, 10); + + if(*end) { + return GARGOYLE_ERR_INVALID_UINT; + } + } + return 0; }