libfuse/lib/util.c
Joanne Koong 535808c4d9 Add libfuse util strtol wrapper
Add a wrapper around strtol for more rigorous error checking
and convert uses of atoi and strtol to use this instead.
2024-10-11 13:15:38 +02:00

28 lines
350 B
C

#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;
}