-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdlib.c
92 lines (71 loc) · 1.52 KB
/
stdlib.c
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
uintptr_t inc(uintptr_t a) {
return a + 1;
}
uintptr_t dec(uintptr_t a) {
return a - 1;
}
void store(uintptr_t ptr, uintptr_t val) {
*(uintptr_t*)(ptr) = val;
}
void storeb(uintptr_t ptr, uintptr_t val) {
*(char*)(ptr) = (char)val;
}
uintptr_t add(uintptr_t a, uintptr_t b) {
return a + b;
}
uintptr_t sub(uintptr_t a, uintptr_t b) {
return a - b;
}
uintptr_t greater(uintptr_t a, uintptr_t b) {
return a > b;
}
uintptr_t less(uintptr_t a, uintptr_t b) {
return a < b;
}
uintptr_t deref(uintptr_t ptr) {
return *(uintptr_t*)(ptr);
}
uintptr_t equal(uintptr_t x, uintptr_t y) {
return x == y;
}
uintptr_t equalchar(uintptr_t x, uintptr_t y) {
return (char)x == (char)y;
}
uintptr_t bnot(uintptr_t x) {
return ~x;
}
uintptr_t not(uintptr_t x) {
return !x;
}
uintptr_t and(uintptr_t x, uintptr_t y) {
return x & y;
}
uintptr_t or(uintptr_t x, uintptr_t y) {
return x | y;
}
uintptr_t xor(uintptr_t x, uintptr_t y) {
return x ^ y;
}
uintptr_t bsprint(uintptr_t a) {
return printf("%li", a);
}
uintptr_t putsnl(uintptr_t ptr) {
return printf("%s\n", (char*)ptr);
}
uintptr_t readfile(uintptr_t path) {
FILE* f = fopen((char*)path, "r");
fseek(f, 0, SEEK_END);
long sz = ftell(f);
fseek(f, 0, SEEK_SET);
char* str = malloc(sz + 1);
fread(str, 1, sz, f);
fclose(f);
str[sz] = '\0';
return (uintptr_t)str;
}
uintptr_t sizeptr(uintptr_t unused) {
return sizeof(void*);
}