Initial commit.
[b43-tools.git] / ssb_sprom / utils.h
1 #ifndef SSB_SPROMTOOL_UTILS_H_
2 #define SSB_SPROMTOOL_UTILS_H_
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <stdint.h>
7
8 #define ssb_stringify_1(x)      #x
9 #define ssb_stringify(x)        ssb_stringify_1(x)
10
11 #ifdef ATTRIBUTE_FORMAT
12 # undef ATTRIBUTE_FORMAT
13 #endif
14 #ifdef __GNUC__
15 # define ATTRIBUTE_FORMAT(t, a, b)      __attribute__((format(t, a, b)))
16 #else
17 # define ATTRIBUTE_FORMAT(t, a, b)      /* nothing */
18 #endif
19
20 int prinfo(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
21 int prerror(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
22 int prdata(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
23
24 void internal_error(const char *message);
25 #define internal_error_on(condition) \
26         do {                                                            \
27                 if (condition)                                          \
28                         internal_error(ssb_stringify(condition));       \
29         } while (0)
30
31 void * malloce(size_t size);
32 void * realloce(void *ptr, size_t newsize);
33
34 /* CRC-8 with polynomial x^8+x^7+x^6+x^4+x^2+1 */
35 uint8_t crc8(uint8_t crc, uint8_t data);
36
37 #endif /* SSB_SPROMTOOL_UTILS_H_ */