diff --git a/cutils.c b/cutils.c index 142347d6acb..9f124f5ea32 100644 --- a/cutils.c +++ b/cutils.c @@ -95,3 +95,14 @@ time_t mktimegm(struct tm *tm) t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec; return t; } + +int fls(int i) +{ + int bit; + + for (bit=31; bit >= 0; bit--) + if (i & (1 << bit)) + return bit+1; + + return 0; +} diff --git a/qemu-common.h b/qemu-common.h index 74eaa4dfc50..308847a21d0 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -94,6 +94,7 @@ char *pstrcat(char *buf, int buf_size, const char *s); int strstart(const char *str, const char *val, const char **ptr); int stristart(const char *str, const char *val, const char **ptr); time_t mktimegm(struct tm *tm); +int fls(int i); #define qemu_isalnum(c) isalnum((unsigned char)(c)) #define qemu_isalpha(c) isalpha((unsigned char)(c))