summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsource/base/base_arena.c2
-rwxr-xr-xsource/base/base_include.h19
-rw-r--r--source/base/base_os.h37
-rw-r--r--source/base/base_platform.h12
-rw-r--r--source/base/base_rand.h5
-rw-r--r--source/tb/tb.h0
6 files changed, 31 insertions, 44 deletions
diff --git a/source/base/base_arena.c b/source/base/base_arena.c
index 60133e0..8fc8c13 100755
--- a/source/base/base_arena.c
+++ b/source/base/base_arena.c
@@ -110,7 +110,7 @@ arena_resize_align(mem_arena *arena, void *old_memory, u64 new_size, u64 old_siz
110 } 110 }
111 else 111 else
112 { 112 {
113 warn(0); 113 // warn(0);
114 } 114 }
115 115
116 return NULL; 116 return NULL;
diff --git a/source/base/base_include.h b/source/base/base_include.h
index 55ef0db..e70ccf2 100755
--- a/source/base/base_include.h
+++ b/source/base/base_include.h
@@ -19,26 +19,19 @@
19#include "base_arena.h" 19#include "base_arena.h"
20#include "base_stack.h" 20#include "base_stack.h"
21 21
22#include "base_string.h" 22#ifdef BASE_IMPLEMENTATION
23#include "base_string.c" 23#include "base_arena.c"
24 24#endif
25#ifdef BASE_PLATFORM
26#include <X11/X.h>
27#include <X11/Xlib.h>
28#include <X11/keysym.h>
29 25
30#include "base_platform.h"
31 26
32#endif 27#include "base_string.h"
28#include "base_string.c"
33 29
34#include "base_error.h"
35#include "base_os.h" 30#include "base_os.h"
31#include "base_error.h"
36 32
37#include "base_rand.h" 33#include "base_rand.h"
38 34
39#ifdef BASE_IMPLEMENTATION
40#include "base_arena.c"
41#endif
42 35
43 36
44#endif 37#endif
diff --git a/source/base/base_os.h b/source/base/base_os.h
index b87c946..536119e 100644
--- a/source/base/base_os.h
+++ b/source/base/base_os.h
@@ -1,9 +1,6 @@
1#ifndef BASE_OS_H 1#ifndef BASE_OS_H
2#define BASE_OS_H 2#define BASE_OS_H
3 3
4#ifdef OS_LINUX
5
6
7#define STDIN_FD 0 4#define STDIN_FD 0
8#define STDOUT_FD 1 5#define STDOUT_FD 1
9#define STDERR_FD 2 6#define STDERR_FD 2
@@ -22,12 +19,11 @@ load_file(mem_arena *arena, const char *path)
22 s32 file = open(path, O_RDONLY); 19 s32 file = open(path, O_RDONLY);
23 if(file == -1) 20 if(file == -1)
24 { 21 {
25 warn("fialed to open file. path could be invalid"); return (string8){0}; 22 return (string8){0};
26 } 23 }
27 24
28 if(fstat(file, &sbuf) == -1) 25 if(fstat(file, &sbuf) == -1)
29 { 26 {
30 warn("error: fstat failed");
31 close(file); 27 close(file);
32 return (string8){0}; 28 return (string8){0};
33 } 29 }
@@ -52,7 +48,6 @@ write_file(const char *path, string8 data)
52 s32 file = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); 48 s32 file = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
53 if(file == -1) 49 if(file == -1)
54 { 50 {
55 warn("failed to open file for writing. path could be invalid");
56 return (string8){0}; 51 return (string8){0};
57 } 52 }
58 53
@@ -62,7 +57,6 @@ write_file(const char *path, string8 data)
62 s64 err = write(file, data.data + written, data.size - written); 57 s64 err = write(file, data.data + written, data.size - written);
63 if(err == -1) 58 if(err == -1)
64 { 59 {
65 warn("write syscall failed");
66 close(file); 60 close(file);
67 return (string8){0}; 61 return (string8){0};
68 } 62 }
@@ -74,8 +68,8 @@ write_file(const char *path, string8 data)
74 return result; 68 return result;
75} 69}
76 70
77#define os_write(void const *buf, u64 count) _os_write(STDIN, buf, count) 71#define os_write(buf, count) _os_write(STDIN_FD, buf, count)
78#define os_read(void const *buf, u64 count) _os_read(STDIN, buf, count) 72#define os_read(buf, count) _os_read(STDIN_FD, buf, count)
79 73
80internal s64 74internal s64
81_os_write(s32 fd, void const *buf, u64 count) 75_os_write(s32 fd, void const *buf, u64 count)
@@ -90,26 +84,26 @@ _os_read(s32 fd, void *buf, u64 count)
90} 84}
91 85
92internal void 86internal void
93print_s8(string8 s) 87log_s8(string8 s)
94{ 88{
95 os_write(s.data, s.size); 89 os_write(s.data, s.size);
96} 90}
97 91
98internal void 92internal void
99print(const char *str) 93_log(const char *str)
100{ 94{
101 s32 len = 0; 95 s32 len = 0;
102 while (str[len]) len++; 96 while (str[len]) len++;
103 os_write(STDOUT_FILENO, str, len); 97 os_write(str, len);
104 98
105} 99}
106 100
107internal void 101internal void
108write_string(s32 fd, const char *str) 102write_string(const char *str)
109{ 103{
110 s32 len = 0; 104 s32 len = 0;
111 while (str[len]) len++; 105 while (str[len]) len++;
112 os_write(fd, str, len); 106 os_write(str, len);
113} 107}
114 108
115internal void 109internal void
@@ -128,5 +122,18 @@ write_int(s32 num)
128 write(STDERR_FILENO, &digit, 1); 122 write(STDERR_FILENO, &digit, 1);
129} 123}
130 124
131#endif 125internal inline void
126sleep_ms(long ms)
127{
128 struct timespec ts;
129 ts.tv_sec = ms / 1000;
130 ts.tv_nsec = (ms % 1000) * 1000000L;
131
132 while (nanosleep(&ts, &ts))
133 {
134 NULL;
135 }
136}
137
138
132#endif 139#endif
diff --git a/source/base/base_platform.h b/source/base/base_platform.h
index 91cd55d..b34a7d0 100644
--- a/source/base/base_platform.h
+++ b/source/base/base_platform.h
@@ -2,17 +2,5 @@
2#define BASE_PLATFORM_H 2#define BASE_PLATFORM_H
3 3
4#ifdef BASE_PLATFORM_IMPLEMENTATION 4#ifdef BASE_PLATFORM_IMPLEMENTATION
5internal inline void
6sleep_ms(long ms)
7{
8 struct timespec ts;
9 ts.tv_sec = ms / 1000;
10 ts.tv_nsec = (ms % 1000) * 1000000L;
11
12 while (nanosleep(&ts, &ts))
13 {
14 NULL;
15 }
16}
17#endif /* BASE_PLATFORM_IMPLEMENTATION */ 5#endif /* BASE_PLATFORM_IMPLEMENTATION */
18#endif /* BASE_PLATFORM_H */ 6#endif /* BASE_PLATFORM_H */
diff --git a/source/base/base_rand.h b/source/base/base_rand.h
index 86acafe..bfdab0f 100644
--- a/source/base/base_rand.h
+++ b/source/base/base_rand.h
@@ -12,9 +12,8 @@
12internal u64 12internal u64
13generate_random_u64(u64 constant) 13generate_random_u64(u64 constant)
14{ 14{
15 15 time_t current_time = time(0);
16 time_t current_time = time(NULL); 16 constant = current_time ^ constant;
17 return current_time ^ constant;
18 17
19 constant += 0x9e3779b97f4a7c15; 18 constant += 0x9e3779b97f4a7c15;
20 19
diff --git a/source/tb/tb.h b/source/tb/tb.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/tb/tb.h