Common

Includes:
<stdint.h>
<stdbool.h>
<stdlib.h>
<stdio.h>
<string.h>
<ctype.h>
<pthread.h>
<time.h>

Introduction

This header contains common defines, macros and functions to be shared throughout the WAC project.



Groups

BitRotates

Rotates X COUNT bits to the left or right.

 

ctype safe macros

Wrappers for the ctype.h macros make them safe when used with signed characters.

Discussion

Some implementations of the ctype.h macros use the character value to directly index into a table. This can lead to crashes and other problems when used with signed characters if the character value is greater than 127 because the values 128-255 will appear to be negative if viewed as a signed char. A negative subscript to an array causes it to index before the beginning and access invalid memory.

To work around this, these *_safe wrappers mask the value and cast it to an unsigned char.

Group members:

BitArray_MinBytes

Macros for working with bit arrays.


Functions

BitArray

Macros for working with bit arrays.

Max

Returns the greater of X and Y.

Min

Returns the lesser of X and Y.


BitArray


Macros for working with bit arrays.

#define BitArray_MinBytes( ARRAY, N_BYTES ) memrlen( (ARRAY), (N_BYTES) ) 
Discussion

This treats bit numbers starting from the left so bit 0 is 0x80 in byte 0, bit 1 is 0x40 in bit 0, bit 8 is 0x80 in byte 1, etc. For example, the following ASCII art shows how the bits are arranged:

1 1 1 1 1 1 1 1 1 1 2 2 2 2 Bit 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | x |x | x x| = 0x20 0x80 0x41 (bits 2, 8, 17, and 23). +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Byte 0 1 2

See Also

BitArray_MinBytes


Max


Returns the greater of X and Y.

#if( !defined( Max ) ) 
#define Max( X, Y )  
#endif  

Min


Returns the lesser of X and Y.

#if( !defined( Min ) ) 
#define Min( X, Y )  
#endif  

Macro Definitions

BitArray_MinBytes

Macros for working with bit arrays.


BitArray_MinBytes


Macros for working with bit arrays.

#define BitArray_MinBytes( ARRAY, N_BYTES ) memrlen( (ARRAY), (N_BYTES) ) 
Discussion

This treats bit numbers starting from the left so bit 0 is 0x80 in byte 0, bit 1 is 0x40 in bit 0, bit 8 is 0x80 in byte 1, etc. For example, the following ASCII art shows how the bits are arranged:

1 1 1 1 1 1 1 1 1 1 2 2 2 2 Bit 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | x |x | x x| = 0x20 0x80 0x41 (bits 2, 8, 17, and 23). +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Byte 0 1 2

See Also

BitArray