skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

bitarray_testandpoke.c (253B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/bitarray.h>
      4 
      5 int bitarray_testandpoke (unsigned char *s, size_t n, int h)
      6 {
      7   unsigned char mask = 1 << (n & 7) ;
      8   unsigned char c = s[n>>3] ;
      9   s[n>>3] = h ? c | mask : c & ~mask ;
     10   return (c & mask) ? 1 : 0 ;
     11 }