forked from Yona-Appletree/LEDscape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.h
executable file
·63 lines (51 loc) · 1.07 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
55
56
57
58
59
60
61
62
63
/** \file
* Utility functions.
*/
#ifndef _util_h_
#define _util_h_
#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
);
extern size_t strlcpy(char *dst, const char *src, size_t size);
extern size_t strlcat(char *dst, const char *src, size_t size);
#endif