From: Lennart Poettering Date: Tue, 6 Apr 2010 21:37:20 +0000 (+0200) Subject: util: when parsing strings lookup tables accept integer strings, too X-Git-Tag: 0.git+20100605+dfd8ee-1~243 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3725859f3d80972d7da3a73b92e58a06ac7d69a;p=systemd util: when parsing strings lookup tables accept integer strings, too --- diff --git a/util.h b/util.h index 273ece89..af39accc 100644 --- a/util.h +++ b/util.h @@ -163,10 +163,14 @@ bool ignore_file(const char *filename); } \ type name##_from_string(const char *s) { \ type i; \ + unsigned u; \ assert(s); \ for (i = 0; i < (type)ELEMENTSOF(name##_table); i++) \ if (streq(name##_table[i], s)) \ return i; \ + if (safe_atou(s, &u) >= 0 && \ + u < ELEMENTSOF(name##_table)) \ + return (type) u; \ return (type) -1; \ } \ struct __useless_struct_to_allow_trailing_semicolon__