Find the first bit clear in bit string at or after bit start. */
| 229 | |
| 230 | /* Find the first bit clear in bit string at or after bit start. */ |
| 231 | static inline void |
| 232 | bit_ffc_at(bitstr_t *_bitstr, int _start, int _nbits, int *_result) |
| 233 | { |
| 234 | bitstr_t *_curbitstr; |
| 235 | bitstr_t *_stopbitstr; |
| 236 | bitstr_t _test; |
| 237 | int _value, _offset; |
| 238 | |
| 239 | if (_start >= _nbits) { |
| 240 | *_result = -1; |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | if (_nbits > 0) { |
| 245 | _curbitstr = _bitstr + _bit_idx(_start); |
| 246 | _stopbitstr = _bitstr + _bit_idx(_nbits - 1); |
| 247 | |
| 248 | _test = *_curbitstr; |
| 249 | if (_bit_offset(_start) != 0) |
| 250 | _test |= _bit_make_mask(0, _start - 1); |
| 251 | while (_test == _BITSTR_MASK && _curbitstr < _stopbitstr) |
| 252 | _test = *(++_curbitstr); |
| 253 | |
| 254 | _offset = ffsl(~_test); |
| 255 | _value = ((_curbitstr - _bitstr) * _BITSTR_BITS) + _offset - 1; |
| 256 | if (_offset == 0 || _value >= _nbits) |
| 257 | _value = -1; |
| 258 | } else { |
| 259 | _value = -1; |
| 260 | } |
| 261 | *_result = _value; |
| 262 | } |
| 263 | |
| 264 | /* Find the first bit set in bit string. */ |
| 265 | static inline void |
no test coverage detected