diff options
Diffstat (limited to 'lib/util.c')
-rw-r--r-- | lib/util.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/util.c b/lib/util.c new file mode 100644 index 0000000..a529d38 --- /dev/null +++ b/lib/util.c @@ -0,0 +1,27 @@ +#include <stdlib.h> +#include <errno.h> + +#include "util.h" + +int libfuse_strtol(const char *str, long *res) +{ + char *endptr; + int base = 10; + long val; + + errno = 0; + + if (!str) + return -EINVAL; + + val = strtol(str, &endptr, base); + + if (errno) + return -errno; + + if (endptr == str || *endptr != '\0') + return -EINVAL; + + *res = val; + return 0; +} |