mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-07 16:59:08 +00:00
utils: add lxc_safe_long()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
This commit is contained in:
parent
0406409813
commit
8c57d93034
@ -2007,7 +2007,7 @@ int lxc_safe_uint(const char *numstr, unsigned int *converted)
|
|||||||
if (uli > UINT_MAX)
|
if (uli > UINT_MAX)
|
||||||
return -ERANGE;
|
return -ERANGE;
|
||||||
|
|
||||||
*converted = (unsigned)uli;
|
*converted = (unsigned int)uli;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2030,3 +2030,23 @@ int lxc_safe_int(const char *numstr, int *converted)
|
|||||||
*converted = (int)sli;
|
*converted = (int)sli;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lxc_safe_long(const char *numstr, long int *converted)
|
||||||
|
{
|
||||||
|
char *err = NULL;
|
||||||
|
signed long int sli;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
sli = strtol(numstr, &err, 0);
|
||||||
|
if (errno > 0)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
if (!err || err == numstr || *err != '\0')
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (sli > LONG_MAX)
|
||||||
|
return -ERANGE;
|
||||||
|
|
||||||
|
*converted = sli;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -320,5 +320,6 @@ 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);
|
int lxc_safe_uint(const char *numstr, unsigned int *converted);
|
||||||
int lxc_safe_int(const char *numstr, int *converted);
|
int lxc_safe_int(const char *numstr, int *converted);
|
||||||
|
int lxc_safe_long(const char *numstr, long int *converted);
|
||||||
|
|
||||||
#endif /* __LXC_UTILS_H */
|
#endif /* __LXC_UTILS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user