return 1;
}
+static int
+vshCommandOptUIntInternal(const vshCmd *cmd,
+ const char *name,
+ unsigned int *value,
+ bool wrap)
+{
+ vshCmdOpt *arg;
+ int ret;
+
+ if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0)
+ return ret;
+
+ if (wrap) {
+ if (virStrToLong_ui(arg->data, NULL, 10, value) < 0)
+ return -1;
+ } else {
+ if (virStrToLong_uip(arg->data, NULL, 10, value) < 0)
+ return -1;
+ }
+
+ return 1;
+}
/**
* vshCommandOptUInt:
* @name option name
* @value result
*
- * Convert option to unsigned int
+ * Convert option to unsigned int, reject negative numbers
* See vshCommandOptInt()
*/
int
vshCommandOptUInt(const vshCmd *cmd, const char *name, unsigned int *value)
{
- vshCmdOpt *arg;
- int ret;
-
- ret = vshCommandOpt(cmd, name, &arg, true);
- if (ret <= 0)
- return ret;
+ return vshCommandOptUIntInternal(cmd, name, value, false);
+}
- if (virStrToLong_ui(arg->data, NULL, 10, value) < 0)
- return -1;
- return 1;
+/**
+ * vshCommandOptUIntWrap:
+ * @cmd command reference
+ * @name option name
+ * @value result
+ *
+ * Convert option to unsigned int, wraps negative numbers to positive
+ * See vshCommandOptInt()
+ */
+int
+vshCommandOptUIntWrap(const vshCmd *cmd, const char *name, unsigned int *value)
+{
+ return vshCommandOptUIntInternal(cmd, name, value, true);
}
int vshCommandOptUInt(const vshCmd *cmd, const char *name,
unsigned int *value)
ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
+int vshCommandOptUIntWrap(const vshCmd *cmd, const char *name,
+ unsigned int *value)
+ ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
int vshCommandOptUL(const vshCmd *cmd, const char *name,
unsigned long *value)
ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;