datapath: Eliminate 'flags' member from odp_flow.
[openvswitch] / lib / util.c
index 12403cbbcf4d35e132cbe48ac40255380a97c2d1..d6e470c92f55f5f041db20bf9ffd84ff46d1e275 100644 (file)
@@ -27,6 +27,8 @@
 
 VLOG_DEFINE_THIS_MODULE(util);
 
+COVERAGE_DEFINE(util_xalloc);
+
 const char *program_name;
 
 void
@@ -364,6 +366,33 @@ hexit_value(int c)
     }
 }
 
+/* Returns the integer value of the 'n' hexadecimal digits starting at 's', or
+ * UINT_MAX if one of those "digits" is not really a hex digit.  If 'ok' is
+ * nonnull, '*ok' is set to true if the conversion succeeds or to false if a
+ * non-hex digit is detected. */
+unsigned int
+hexits_value(const char *s, size_t n, bool *ok)
+{
+    unsigned int value;
+    size_t i;
+
+    value = 0;
+    for (i = 0; i < n; i++) {
+        int hexit = hexit_value(s[i]);
+        if (hexit < 0) {
+            if (ok) {
+                *ok = false;
+            }
+            return UINT_MAX;
+        }
+        value = (value << 4) + hexit;
+    }
+    if (ok) {
+        *ok = true;
+    }
+    return value;
+}
+
 /* Returns the current working directory as a malloc()'d string, or a null
  * pointer if the current working directory cannot be determined. */
 char *