X-Git-Url: http://git.droids-corp.org/?p=protos%2Flibecoli.git;a=blobdiff_plain;f=src%2Fecoli_node_int.c;fp=src%2Fecoli_node_int.c;h=80f2fd56d69ef9ba84af39e5a55e2b3385a94ccd;hp=9b56e220023f72f392fed67cb14405065b930b2c;hb=a83942778fc85ad92db9082cf0d7c2d958d98aaf;hpb=e900ed6e1cb162855289bc7a9acc9b3d1af9d697 diff --git a/src/ecoli_node_int.c b/src/ecoli_node_int.c index 9b56e22..80f2fd5 100644 --- a/src/ecoli_node_int.c +++ b/src/ecoli_node_int.c @@ -18,8 +18,9 @@ #include #include #include -#include +#include #include +#include EC_LOG_TYPE_REGISTER(node_int); @@ -40,68 +41,38 @@ struct ec_node_int_uint { unsigned int base; }; -/* XXX to utils.c ? */ static int parse_llint(struct ec_node_int_uint *node, const char *str, int64_t *val) { - char *endptr; - int save_errno = errno; - - errno = 0; - *val = strtoll(str, &endptr, node->base); - - if ((errno == ERANGE && (*val == LLONG_MAX || *val == LLONG_MIN)) || - (errno != 0 && *val == 0)) - return -1; - - if (node->check_min && *val < node->min) { - errno = ERANGE; - return -1; - } + int64_t min, max; - if (node->check_max && *val > node->max) { - errno = ERANGE; - return -1; - } - - if (*endptr != 0) { - errno = EINVAL; - return -1; - } + if (node->check_min) + min = node->min; + else + min = LLONG_MIN; + if (node->check_max) + max = node->max; + else + max = LLONG_MAX; - errno = save_errno; - return 0; + return ec_str_parse_llint(str, node->base, min, max, val); } static int parse_ullint(struct ec_node_int_uint *node, const char *str, uint64_t *val) { - char *endptr; - int save_errno = errno; - - /* since a negative input is silently converted to a positive - * one by strtoull(), first check that it is positive */ - if (strchr(str, '-')) - return -1; + uint64_t min, max; - errno = 0; - *val = strtoull(str, &endptr, node->base); - - if ((errno == ERANGE && *val == ULLONG_MAX) || - (errno != 0 && *val == 0)) - return -1; - - if (node->check_min && *val < node->umin) - return -1; - - if (node->check_max && *val > node->umax) - return -1; - - if (*endptr != 0) - return -1; + if (node->check_min) + min = node->min; + else + min = 0; + if (node->check_max) + max = node->max; + else + max = ULLONG_MAX; - errno = save_errno; - return 0; + return ec_str_parse_ullint(str, node->base, min, max, val); } static int ec_node_int_uint_parse(const struct ec_node *gen_node,