cogl-util: Add an internal wrapper for the ffs function

The ffs function is defined in C99 so if we want to use it in Cogl we
need to provide a fallback for MSVC. This adds a configure check for
the function and then a fallback using a while loop if it is not
available.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2491
This commit is contained in:
Neil Roberts
2010-12-17 16:06:10 +00:00
parent 0b2dc74dbc
commit 14e94647bf
2 changed files with 29 additions and 0 deletions

View File

@ -218,3 +218,24 @@ _cogl_util_one_at_a_time_mix (unsigned int hash)
return hash;
}
/* The 'ffs' function is part of C99 so it isn't always available */
#ifndef HAVE_FFS
int
_cogl_util_ffs (int num)
{
int i = 1;
if (num == 0)
return 0;
while ((num & 1) == 0)
{
num >>= 1;
i++;
}
return i;
}
#endif /* HAVE_FFS */