summaryrefslogtreecommitdiff
path: root/source/base/base_os.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/base/base_os.h')
-rw-r--r--source/base/base_os.h31
1 files changed, 8 insertions, 23 deletions
diff --git a/source/base/base_os.h b/source/base/base_os.h
index 82aa70d..2e192c5 100644
--- a/source/base/base_os.h
+++ b/source/base/base_os.h
@@ -15,7 +15,6 @@ load_file(mem_arena *arena, const char *path)
15 string8 result = {0}; 15 string8 result = {0};
16 struct stat sbuf = {0}; 16 struct stat sbuf = {0};
17 17
18 // TODO(nasr): abstract this to a platform layer
19 s32 file = open(path, O_RDONLY); 18 s32 file = open(path, O_RDONLY);
20 if(file == -1) 19 if(file == -1)
21 { 20 {
@@ -28,9 +27,7 @@ load_file(mem_arena *arena, const char *path)
28 return (string8){0}; 27 return (string8){0};
29 } 28 }
30 29
31
32 result = PushString8(arena, sbuf.st_size); 30 result = PushString8(arena, sbuf.st_size);
33
34 result.size = (u64)sbuf.st_size; 31 result.size = (u64)sbuf.st_size;
35 if(result.size != 0) 32 if(result.size != 0)
36 { 33 {
@@ -68,8 +65,9 @@ write_file(const char *path, string8 data)
68 return result; 65 return result;
69} 66}
70 67
71#define os_write(buf, count) _os_write(STDIN_FD, buf, count) 68#if 0
72#define os_read(buf, count) _os_read(STDIN_FD, buf, count) 69#define os_write(buf, count) _os_write(STDOUT_FD, buf, count)
70#define os_read(buf, count) _os_read(STDIN_FD, buf, count)
73 71
74internal s64 72internal s64
75_os_write(s32 fd, void const *buf, u64 count) 73_os_write(s32 fd, void const *buf, u64 count)
@@ -83,6 +81,7 @@ _os_read(s32 fd, void *buf, u64 count)
83 return syscall(SYS_read, fd, buf, count); 81 return syscall(SYS_read, fd, buf, count);
84} 82}
85 83
84
86internal void 85internal void
87log_s8(string8 s) 86log_s8(string8 s)
88{ 87{
@@ -100,10 +99,10 @@ _log(const char *str)
100#else 99#else
101 unused(str); 100 unused(str);
102#endif 101#endif
103
104} 102}
105#endif 103#endif
106 104
105
107internal void 106internal void
108write_string(const char *str) 107write_string(const char *str)
109{ 108{
@@ -112,10 +111,11 @@ write_string(const char *str)
112 os_write(str, len); 111 os_write(str, len);
113} 112}
114 113
114#endif
115
115internal void 116internal void
116write_int(s32 num) 117write_int(s32 num)
117{ 118{
118
119 if (num < 0) 119 if (num < 0)
120 { 120 {
121 write(STDERR_FILENO, "-", 1); 121 write(STDERR_FILENO, "-", 1);
@@ -124,22 +124,7 @@ write_int(s32 num)
124 if (num >= 10) write_int(num / 10); 124 if (num >= 10) write_int(num / 10);
125 125
126 char digit = '0' + (num % 10); 126 char digit = '0' + (num % 10);
127
128 write(STDERR_FILENO, &digit, 1); 127 write(STDERR_FILENO, &digit, 1);
129} 128}
130 129
131internal inline void 130#endif /* BASE_IMPLEMENTATION */
132sleep_ms(long ms)
133{
134 struct timespec ts;
135 ts.tv_sec = ms / 1000;
136 ts.tv_nsec = (ms % 1000) * 1000000L;
137
138 while (nanosleep(&ts, &ts))
139 {
140 NULL;
141 }
142}
143
144
145#endif