-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
57 lines (48 loc) · 1.02 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
#pragma once
#include <stddef.h>
__attribute__((noreturn))
static inline void hang () {
while(1) {
__asm__ volatile ("hlt");
};
}
static inline int min(int a, int b) {
return a < b ? a : b;
}
static inline int max(int a, int b) {
return a > b ? a : b;
}
static inline uint64_t align_up(uint64_t val, uint64_t al) {
if (val % al) {
val += al - val%al;
}
return val;
}
static inline void barrier() {
__asm__ volatile ("" : : : "memory");
}
static inline size_t strlen(const char * str) {
size_t res = 0;
while (str[res] != 0) {
++res;
}
return res;
}
static inline int strncmp (const char * from, const char * to, size_t len) {
unsigned int i = 0;
for (;from[i] == to[i] && from[i] != 0 && i < len; ++i){
}
if (from[i] == 0 && to[i] == 0) {
return 0;
}
if (i == len) {
return 0;
}
if (from[i] < to[i]) {
return -1;
} else if (from[i] == to[i]) {
return 0;
} else {
return 1;
}
}