#include <lxc/lxccontainer.h>
#include "arguments.h"
-#include "commands.h"
-#include "error.h"
-#include "log.h"
-#include "lxc.h"
-#include "mainloop.h"
-#include "utils.h"
+#include "tool_utils.h"
static char etoc(const char *expr)
{
ret = lxc_log_init(&log);
if (ret)
return EXIT_FAILURE;
- lxc_log_options_no_override();
/* REMOVE IN LXC 3.0 */
setenv("LXC_UPDATE_CONFIG_FORMAT", "1", 0);
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#define _GNU_SOURCE
#define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
+#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
return status;
}
+int lxc_safe_uint(const char *numstr, unsigned int *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;
+
+ if (uli > UINT_MAX)
+ return -ERANGE;
+
+ *converted = (unsigned int)uli;
+ return 0;
+}
+
int lxc_safe_int(const char *numstr, int *converted)
{
char *err = NULL;
extern int wait_for_pid(pid_t pid);
extern int lxc_wait_for_pid_status(pid_t pid);
+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);