-
Notifications
You must be signed in to change notification settings - Fork 0
/
STDC.H
104 lines (82 loc) · 1.51 KB
/
STDC.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
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
93
94
95
96
97
98
99
100
101
102
103
104
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void my_abort(void) {
exit(-1);
}
void my_memcpy(char* dest, char* src, size_t count) {
memcpy(dest, src, count);
}
int my_memcmp(char* dest, char* src, size_t count) {
return memcmp(dest, src, count);
}
void my_strcpy(char* dest, char const* src) {
strcpy(dest, src);
}
void my_strncpy(char* dest, char* src, size_t dest_size) {
strncpy(dest, src, dest_size);
}
void my_strcat(char* dest, char* src) {
strcat(dest, src);
}
size_t my_strlen(char* str) {
return strlen(str);
}
int my_strncmp(char* dest, char* src, size_t count) {
return strncmp(dest, src, count);
}
char* my_utoa(uint32_t value) {
static char buf[11];
sprintf(buf, "%u", value);
return buf;
}
void print(char *string) {
char* end = memchr(string, '$', SIZE_MAX);
if (end) {
fwrite(string, end - string, 1, stdout);
}
}
FILE* f;
int creat(char *filename) {
f = fopen(filename, "w+b");
if (f) {
return 1;
}
else {
return 0;
}
}
int open(char *filename) {
f = fopen(filename, "r+b");
if (f) {
return 1;
}
else {
return 0;
}
}
int lseek(int handle, int pos, int whence) {
return fseek(f, pos, whence);
}
int read(int handle, void *output, int count) {
return fread(output, 1, count, f);
}
int write(int handle, void *data, int count) {
return fwrite(data, 1, count, f);
}
int close(int handle) {
fclose(f);
}
uint8_t getch(void) {
int c = getchar();
if (c < 0) {
return 0x1A;
}
else if (c == '\n') {
return '\r';
}
else {
return c;
}
}