mirror of
https://github.com/libfuse/libfuse.git
synced 2024-11-23 04:04:31 +08:00
535808c4d9
Add a wrapper around strtol for more rigorous error checking and convert uses of atoi and strtol to use this instead.
28 lines
350 B
C
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;
|
|
}
|