-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathformat.h
More file actions
77 lines (62 loc) · 2.3 KB
/
format.h
File metadata and controls
77 lines (62 loc) · 2.3 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <cdefs.h>
#define FMTUSE(p, e, buf, len) \
char* p = buf; \
char* e = buf + len - 1;
#define FMTBUF(p, e, buf, len) \
char buf[len+1];\
char* p = buf;\
char* e = buf + sizeof(buf) - 1;
#define FMTEND(p, e) \
*p = '\0';
#define FMTENL(p, e) \
if(p < e) *p++ = '\n';
/* Note FMTENL is used to produce a buffer suitable for
write()-ing to STDOUT, *not* a 0-terminated string. */
struct tm;
char* fmtraw(char* p, char* e, const void* data, int len);
char* fmterr(char* p, char* e, int err);
char* fmtbyte(char* p, char* e, char c);
char* fmtbytes(char* p, char* e, const void* data, uint len);
char* fmti32(char* p, char* e, int32_t num);
char* fmtu32(char* p, char* e, uint32_t num);
char* fmtx32(char* p, char* e, uint32_t num);
char* fmti64(char* p, char* e, int64_t num);
char* fmtu64(char* p, char* e, uint64_t num);
char* fmtx64(char* p, char* e, uint64_t num);
char* fmtint(char* p, char* e, int num);
char* fmtuint(char* p, char* e, uint num);
char* fmtxint(char* p, char* e, uint num);
char* fmtlong(char* p, char* e, long num);
char* fmtulong(char* p, char* e, ulong num);
char* fmtxlong(char* p, char* e, ulong num);
char* fmthex(char* p, char* e, uint n);
char* fmtpad(char* p, char* e, int width, char* q);
char* fmtpad0(char* p, char* e, int width, char* q);
char* fmtpadr(char* p, char* e, int width, char* q);
char* fmtsize(char* p, char* e, uint64_t n);
char* fmtstr(char* p, char* e, const char* src);
char* fmtstrn(char* p, char* e, const char* src, int len);
char* fmtstrl(char* p, char* e, const char* src, int len);
char* fmttm(char* p, char* e, const struct tm* tm);
char* fmtulp(char* p, char* e, ulong num, int pad);
char* fmtip(char* p, char* e, uint8_t ip[4]);
char* fmtmac(char* p, char* e, uint8_t mac[6]);
char* parseint(char* p, int* np);
char* parseuint(char* p, uint* np);
char* parselong(char* p, long* np);
char* parseulong(char* p, ulong* np);
char* parseu64(char* p, uint64_t* np);
char* parsebyte(char* p, byte* v);
char* parsebytes(char* p, byte* buf, uint len);
char* parseoct(char* p, int* np);
char* parsehex(char* p, int* np);
char* parsexlong(char* p, ulong* np);
char* parsemac(char* p, byte* mac);
char* parseip(char* p, byte* ip);
char* parseipmask(char* p, byte* ip, byte* mask);
static inline char* fmtchar(char* p, char* e, char c)
{
if(p < e)
*p++ = c;
return p;
};