X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Futil.c;fp=lib%2Futil.c;h=1ebe22a5c7a09756eab2ad95b081289233f2a3ea;hb=7d78f21c057ff50a823220d809ac38c3d907243c;hp=3f08c4ac864f363ce70eafd7c3a6556535dee998;hpb=8d25251929c8f325bed0fff24192d5a87034b32e;p=sliver-openvswitch.git diff --git a/lib/util.c b/lib/util.c index 3f08c4ac8..1ebe22a5c 100644 --- a/lib/util.c +++ b/lib/util.c @@ -613,6 +613,20 @@ str_to_llong(const char *s, int base, long long *x) } } +bool +str_to_uint(const char *s, int base, unsigned int *u) +{ + long long ll; + bool ok = str_to_llong(s, base, &ll); + if (!ok || ll < 0 || ll > UINT_MAX) { + *u = 0; + return false; + } else { + *u = ll; + return true; + } +} + /* Converts floating-point string 's' into a double. If successful, stores * the double in '*d' and returns true; on failure, stores 0 in '*d' and * returns false.