summaryrefslogtreecommitdiffstats
path: root/ssb_sprom/utils.h
blob: bd60f9879ede88a39ecc916d3267d1a9c2a4e32a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef SSB_SPROMTOOL_UTILS_H_
#define SSB_SPROMTOOL_UTILS_H_

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#define ssb_stringify_1(x)	#x
#define ssb_stringify(x)	ssb_stringify_1(x)

#ifdef ATTRIBUTE_FORMAT
# undef ATTRIBUTE_FORMAT
#endif
#ifdef __GNUC__
# define ATTRIBUTE_FORMAT(t, a, b)	__attribute__((format(t, a, b)))
#else
# define ATTRIBUTE_FORMAT(t, a, b)	/* nothing */
#endif

int prinfo(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
int prerror(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
int prdata(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);

void internal_error(const char *message);
#define internal_error_on(condition) \
	do {								\
		if (condition)						\
			internal_error(ssb_stringify(condition));	\
	} while (0)

void * malloce(size_t size);
void * realloce(void *ptr, size_t newsize);

/* CRC-8 with polynomial x^8+x^7+x^6+x^4+x^2+1 */
uint8_t crc8(uint8_t crc, uint8_t data);

#endif /* SSB_SPROMTOOL_UTILS_H_ */
bues.ch cgit interface