summaryrefslogtreecommitdiff
path: root/src/libstddjb/bitarray_testandpoke.c
blob: f12653af793213abc2abcf6ba8abb18762f21376 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
/* ISC license. */

#include <sys/types.h>
#include <skalibs/bitarray.h>

int bitarray_testandpoke (unsigned char *s, size_t n, int h)
{
  unsigned char mask = 1 << (n & 7) ;
  unsigned char c = s[n>>3] ;
  s[n>>3] = h ? c | mask : c & ~mask ;
  return (c & mask) ? 1 : 0 ;
}