libcoap  4.2.1
bits.h
Go to the documentation of this file.
1 /*
2  * bits.h -- bit vector manipulation
3  *
4  * Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
5  *
6  * This file is part of the CoAP library libcoap. Please see README for terms
7  * of use.
8  */
9 
15 #ifndef COAP_BITS_H_
16 #define COAP_BITS_H_
17 
18 #include <stdint.h>
19 
32 bits_setb(uint8_t *vec, size_t size, uint8_t bit) {
33  if (size <= ((size_t)bit >> 3))
34  return -1;
35 
36  *(vec + (bit >> 3)) |= (uint8_t)(1 << (bit & 0x07));
37  return 1;
38 }
39 
52 bits_clrb(uint8_t *vec, size_t size, uint8_t bit) {
53  if (size <= ((size_t)bit >> 3))
54  return -1;
55 
56  *(vec + (bit >> 3)) &= (uint8_t)(~(1 << (bit & 0x07)));
57  return 1;
58 }
59 
71 bits_getb(const uint8_t *vec, size_t size, uint8_t bit) {
72  if (size <= ((size_t)bit >> 3))
73  return -1;
74 
75  return (*(vec + (bit >> 3)) & (1 << (bit & 0x07))) != 0;
76 }
77 
78 #endif /* COAP_BITS_H_ */
COAP_STATIC_INLINE int bits_clrb(uint8_t *vec, size_t size, uint8_t bit)
Clears the bit bit from bit-vector vec.
Definition: bits.h:52
#define COAP_STATIC_INLINE
Definition: libcoap.h:38
COAP_STATIC_INLINE int bits_setb(uint8_t *vec, size_t size, uint8_t bit)
Sets the bit bit in bit-vector vec.
Definition: bits.h:32
COAP_STATIC_INLINE int bits_getb(const uint8_t *vec, size_t size, uint8_t bit)
Gets the status of bit bit from bit-vector vec.
Definition: bits.h:71
unsigned char uint8_t
Definition: uthash.h:79