utils: add lxc_safe_long_long()

parent f3d05ee6
......@@ -2003,6 +2003,26 @@ int lxc_safe_long(const char *numstr, long int *converted)
return 0;
}
int lxc_safe_long_long(const char *numstr, long long int *converted)
{
char *err = NULL;
signed long long int sli;
errno = 0;
sli = strtoll(numstr, &err, 0);
if (errno == ERANGE && (sli == LLONG_MAX || sli == LLONG_MIN))
return -ERANGE;
if (errno != 0 && sli == 0)
return -EINVAL;
if (err == numstr || *err != '\0')
return -EINVAL;
*converted = sli;
return 0;
}
int lxc_switch_uid_gid(uid_t uid, gid_t gid)
{
if (setgid(gid) < 0) {
......
......@@ -419,6 +419,7 @@ extern bool task_blocking_signal(pid_t pid, int signal);
extern int lxc_safe_uint(const char *numstr, unsigned int *converted);
extern int lxc_safe_int(const char *numstr, int *converted);
extern int lxc_safe_long(const char *numstr, long int *converted);
extern int lxc_safe_long_long(const char *numstr, long long int *converted);
extern int lxc_safe_ulong(const char *numstr, unsigned long *converted);
/* Switch to a new uid and gid. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment