22 lines
376 B
C
22 lines
376 B
C
#include <errno.h>
|
|
#include <inttypes.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
int
|
|
cli_parse_int64(const char *s, int64_t *out)
|
|
{
|
|
char *end;
|
|
|
|
if (NULL == s || '\0' == *s)
|
|
return 1;
|
|
|
|
errno = 0;
|
|
const intmax_t v = strtoimax(s, &end, 10);
|
|
|
|
if (s == end || ERANGE == errno || '\0' != *end || v < INT64_MIN || v > INT64_MAX)
|
|
return 1;
|
|
|
|
*out = (int64_t)v;
|
|
return 0;
|
|
}
|