1 //-----------------------------------------------------------------------------
2 // Jonathan Westhues, Aug 2005
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
8 // Utility functions used in many places, not specific to any piece of code.
9 //-----------------------------------------------------------------------------
11 #ifndef __COMMONUTIL_H
12 #define __COMMONUTIL_H
16 // endian change for 16bit
19 #define BSWAP_16(x) __builtin_bswap16(x)
24 #define BSWAP_16(x) _byteswap_ushort(x)
28 # define BSWAP_16(x) ((( ((x) & 0xFF00 ) >> 8))| ( (((x) & 0x00FF) << 8)))
34 # define BITMASK(X) (1 << (X))
37 # define ARRAYLEN(x) (sizeof(x)/sizeof((x)[0]))
41 # define NTIME(n) for (int _index = 0; _index < n; _index++)
44 extern struct version_information version_information
;
45 void FormatVersionInformation(char *dst
, int len
, const char *prefix
, void *version_info
);
47 uint32_t reflect(uint32_t v
, int b
); // used in crc.c ...
48 uint8_t reflect8(uint8_t b
); // dedicated 8bit reversal
49 uint16_t reflect16(uint16_t b
); // dedicated 16bit reversal
50 uint32_t reflect32(uint32_t b
); // dedicated 32bit reversal
52 void num_to_bytes(uint64_t n
, size_t len
, uint8_t *dest
);
53 uint64_t bytes_to_num(uint8_t *src
, size_t len
);
55 // rotate left byte array
56 void rol(uint8_t *data
, const size_t len
);
57 void lsl(uint8_t *data
, size_t len
);
58 uint32_t le24toh(uint8_t data
[3]);
59 void htole24(uint32_t val
, uint8_t data
[3]);
62 uint32_t rotl(uint32_t a
, uint8_t n
);
63 uint32_t rotr(uint32_t a
, uint8_t n
);