Tranform string values into 64-bit unsigned integers

This commit is contained in:
Nick Chambers 2022-06-20 12:51:19 -05:00
parent 88c124f4bc
commit 7d9b89e9f8
2 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -1,6 +1,7 @@
#include <gargoyle/codex.h>
#include <gargoyle/scribe.h>
#include <gargoyle/twine.h>
#include <stdlib.h>
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;
}