Unverified Commit b84663a8 by Christian Brauner Committed by Stéphane Graber

utils: add lxc_safe_ulong()

parent 61e3ec8f
......@@ -2021,6 +2021,29 @@ int lxc_safe_uint(const char *numstr, unsigned int *converted)
return 0;
}
int lxc_safe_ulong(const char *numstr, unsigned long *converted)
{
char *err = NULL;
unsigned long int uli;
while (isspace(*numstr))
numstr++;
if (*numstr == '-')
return -EINVAL;
errno = 0;
uli = strtoul(numstr, &err, 0);
if (errno == ERANGE && uli == ULONG_MAX)
return -ERANGE;
if (err == numstr || *err != '\0')
return -EINVAL;
*converted = uli;
return 0;
}
int lxc_safe_int(const char *numstr, int *converted)
{
char *err = NULL;
......
......@@ -340,6 +340,7 @@ bool task_blocking_signal(pid_t pid, int signal);
int lxc_safe_uint(const char *numstr, unsigned int *converted);
int lxc_safe_int(const char *numstr, int *converted);
int lxc_safe_long(const char *numstr, long int *converted);
int lxc_safe_ulong(const char *numstr, unsigned long *converted);
/* Switch to a new uid and gid. */
int lxc_switch_uid_gid(uid_t uid, gid_t 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