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

#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 ;
}