-
Notifications
You must be signed in to change notification settings - Fork 261
/
util.h
47 lines (38 loc) · 963 Bytes
/
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
#ifndef UTIL_H
#define UTIL_H
#include <stdint.h>
#include <stdbool.h>
#define LENGTH(x) ((int)(sizeof (x) / sizeof *(x)))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
/* is c the start of a utf8 sequence? */
#define ISUTF8(c) (((c)&0xC0)!=0x80)
#define ISASCII(ch) ((unsigned char)ch < 0x80)
#if GCC_VERSION>=5004000 || CLANG_VERSION>=4000000
#define addu __builtin_add_overflow
#else
static inline bool addu(size_t a, size_t b, size_t *c) {
if (SIZE_MAX - a < b)
return false;
*c = a + b;
return true;
}
#endif
#if !HAVE_MEMRCHR
/* MIT licensed implementation from musl libc */
static void *memrchr(const void *m, int c, size_t n)
{
const unsigned char *s = m;
c = (unsigned char)c;
while (n--) if (s[n]==c) return (void *)(s+n);
return 0;
}
#endif
/* Needed for building on GNU Hurd */
#ifndef PIPE_BUF
#define PIPE_BUF 4096
#endif
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
#endif /* UTIL_H */