if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
goto cleanup;
- if (vshCommandOptUL(cmd, "bandwidth", &bandwidth) < 0) {
+ if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) {
vshError(ctl, "%s", _("bandwidth must be a number"));
goto cleanup;
}
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
- if (vshCommandOptUL(cmd, "bandwidth", &bandwidth) < 0) {
+ if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) {
vshError(ctl, "%s", _("migrate: Invalid bandwidth"));
goto done;
}
return vshCommandOptUIntInternal(cmd, name, value, true);
}
+static int
+vshCommandOptULInternal(const vshCmd *cmd,
+ const char *name,
+ unsigned long *value,
+ bool wrap)
+{
+ vshCmdOpt *arg;
+ int ret;
+
+ if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0)
+ return ret;
+
+ if (wrap) {
+ if (virStrToLong_ul(arg->data, NULL, 10, value) < 0)
+ return -1;
+ } else {
+ if (virStrToLong_ulp(arg->data, NULL, 10, value) < 0)
+ return -1;
+ }
+
+ return 1;
+}
/*
* vshCommandOptUL:
int
vshCommandOptUL(const vshCmd *cmd, const char *name, unsigned long *value)
{
- vshCmdOpt *arg;
- int ret;
-
- ret = vshCommandOpt(cmd, name, &arg, true);
- if (ret <= 0)
- return ret;
+ return vshCommandOptULInternal(cmd, name, value, false);
+}
- if (virStrToLong_ul(arg->data, NULL, 10, value) < 0)
- return -1;
- return 1;
+/**
+ * vshCommandOptULWrap:
+ * @cmd command reference
+ * @name option name
+ * @value result
+ *
+ * Convert option to unsigned long, wraps negative numbers to positive
+ * See vshCommandOptInt()
+ */
+int
+vshCommandOptULWrap(const vshCmd *cmd, const char *name, unsigned long *value)
+{
+ return vshCommandOptULInternal(cmd, name, value, true);
}
/**
int vshCommandOptUL(const vshCmd *cmd, const char *name,
unsigned long *value)
ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
+int vshCommandOptULWrap(const vshCmd *cmd, const char *name,
+ unsigned long *value)
+ ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
int vshCommandOptString(const vshCmd *cmd, const char *name,
const char **value)
ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;