X-Git-Url: http://pilppa.org/gitweb/?p=libplp.git;a=blobdiff_plain;f=src%2Fstr_util.c;h=abf521b6622467521484b7c3afdd46b270bad795;hp=aca2fd8488a9a055e919f2e38ebc413e55765b68;hb=860d8c023b82eeca9833d4a3f534c6d11a9523f3;hpb=65f22bbea2531f7cd492d6108b8902f92b7750a8 diff --git a/src/str_util.c b/src/str_util.c index aca2fd8..abf521b 100644 --- a/src/str_util.c +++ b/src/str_util.c @@ -8,6 +8,10 @@ #include #include #include +#include +#include + +#include char *get_as_hex_str(const char *byte_arr, int byte_count) { int ii; @@ -33,3 +37,26 @@ char *get_as_hex_str(const char *byte_arr, int byte_count) { } return ret_val; } + +bool parse_long(const char *str, long *result) { + int new_result; + char *endptr; + bool ret_val; + + ret_val = false; + errno = 0; + new_result = strtol(str, &endptr, 10); + if (errno != 0) { + log_error("invalid input %s, could not convert to integer.\n", str); + } + else { + if (endptr == str) { + log_error("invalid input %s, could not convert to integer.\n", str); + } + else { + *result = new_result; + ret_val = true; + } + } + return ret_val; +}