utils: add lxc_safe_long_long()

parent df0f17ad
...@@ -2061,6 +2061,26 @@ int lxc_safe_long(const char *numstr, long int *converted) ...@@ -2061,6 +2061,26 @@ int lxc_safe_long(const char *numstr, long int *converted)
return 0; 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) int lxc_switch_uid_gid(uid_t uid, gid_t gid)
{ {
if (setgid(gid) < 0) { if (setgid(gid) < 0) {
......
...@@ -407,10 +407,11 @@ int lxc_preserve_ns(const int pid, const char *ns); ...@@ -407,10 +407,11 @@ int lxc_preserve_ns(const int pid, const char *ns);
bool task_blocking_signal(pid_t pid, int signal); bool task_blocking_signal(pid_t pid, int signal);
/* Helper functions to parse numbers. */ /* Helper functions to parse numbers. */
int lxc_safe_uint(const char *numstr, unsigned int *converted); extern int lxc_safe_uint(const char *numstr, unsigned int *converted);
int lxc_safe_int(const char *numstr, int *converted); extern int lxc_safe_int(const char *numstr, int *converted);
int lxc_safe_long(const char *numstr, long int *converted); extern int lxc_safe_long(const char *numstr, long int *converted);
int lxc_safe_ulong(const char *numstr, unsigned long *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. */ /* Switch to a new uid and gid. */
int lxc_switch_uid_gid(uid_t uid, gid_t 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