forked from toroidal-code/PixelBone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.h
54 lines (43 loc) · 1.8 KB
/
util.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/** \file
* Utility functions.
*/
#ifndef _util_h_
#define _util_h_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <inttypes.h>
#include <errno.h>
#include <unistd.h>
#define warn(fmt, ...) \
do { \
fprintf(stderr, "%s:%d: " fmt, __func__, __LINE__, ##__VA_ARGS__); \
} while (0)
#define warn_once(fmt, ...) \
do { \
static unsigned __warned__; \
if (__warned__) \
break; \
__warned__ = 1; \
warn(fmt, ##__VA_ARGS__); \
} while (0)
#define die(fmt, ...) \
do { \
warn(fmt, ##__VA_ARGS__); \
exit(EXIT_FAILURE); \
} while (0)
extern void hexdump(FILE *const outfile, const void *const buf,
const size_t len);
extern int serial_open(const char *const dev);
/** Write all the bytes to a fd, even if there is a brief interruption.
* \return number of bytes written or -1 on any fatal error.
*/
extern ssize_t write_all(const int fd, const void *const buf_ptr,
const size_t len);
#ifdef __cplusplus
}
#endif
#endif