X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Futil.c;h=d6e470c92f55f5f041db20bf9ffd84ff46d1e275;hb=61fe3a7b3b8b628ac70511e6af25bb9f8cb8bc2b;hp=12403cbbcf4d35e132cbe48ac40255380a97c2d1;hpb=e1aff6f9f7103ee59e2501d3e6c705a685b20aeb;p=openvswitch diff --git a/lib/util.c b/lib/util.c index 12403cbb..d6e470c9 100644 --- a/lib/util.c +++ b/lib/util.c @@ -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 *