diff options
Diffstat (limited to 'src/badlib.h')
-rw-r--r-- | src/badlib.h | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/badlib.h b/src/badlib.h index 25e4914..c73b57f 100644 --- a/src/badlib.h +++ b/src/badlib.h | |||
@@ -20,7 +20,9 @@ | |||
20 | #include <stdint.h> | 20 | #include <stdint.h> |
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <strings.h> | 23 | #include <string.h> |
24 | #include <time.h> | ||
25 | #include <unistd.h> | ||
24 | 26 | ||
25 | // | 27 | // |
26 | // Basic types. | 28 | // Basic types. |
@@ -43,7 +45,7 @@ typedef ptrdiff_t sz; | |||
43 | typedef uintptr_t ptrsize; | 45 | typedef uintptr_t ptrsize; |
44 | typedef size_t usize; | 46 | typedef size_t usize; |
45 | 47 | ||
46 | #define KB(N) ((sz)(N)*1024) | 48 | #define KB(N) ((sz)(N) * 1024) |
47 | #define MB(N) ((sz)KB(N) * 1024) | 49 | #define MB(N) ((sz)KB(N) * 1024) |
48 | #define GB(N) ((sz)MB(N) * 1024) | 50 | #define GB(N) ((sz)MB(N) * 1024) |
49 | #define TB(N) ((sz)GB(N) * 1024) | 51 | #define TB(N) ((sz)GB(N) * 1024) |
@@ -287,9 +289,9 @@ buf_pop(Buf *buf, void *dst, sz size) { | |||
287 | typedef Array Str; | 289 | typedef Array Str; |
288 | 290 | ||
289 | // Create a string object from a C literal. | 291 | // Create a string object from a C literal. |
290 | #define cstr(s) \ | 292 | #define cstr(s) \ |
291 | (Str) { \ | 293 | (Str) { \ |
292 | (u8 *)(s), LEN(s) - 1 \ | 294 | .mem = (u8 *)(s), .size = LEN(s) - 1, \ |
293 | } | 295 | } |
294 | 296 | ||
295 | // Create a string object from a char* array. | 297 | // Create a string object from a char* array. |
@@ -345,7 +347,9 @@ str_split_fn(Str *a, StrSplitFn split_fn) { | |||
345 | void | 347 | void |
346 | str_replace(Str *a, Str from, Str to) { | 348 | str_replace(Str *a, Str from, Str to) { |
347 | assert(a != NULL); | 349 | assert(a != NULL); |
348 | assert(from.size == to.size); | 350 | if (from.size != to.size) { |
351 | return; | ||
352 | } | ||
349 | SearchResult res = array_find_next(*a, from); | 353 | SearchResult res = array_find_next(*a, from); |
350 | if (res.found) { | 354 | if (res.found) { |
351 | memcpy(a->mem + res.pos, to.mem, res.matched); | 355 | memcpy(a->mem + res.pos, to.mem, res.matched); |
@@ -945,7 +949,7 @@ _int_eq(sz a, sz b) { | |||
945 | return a == b; | 949 | return a == b; |
946 | } | 950 | } |
947 | 951 | ||
948 | bool | 952 | u64 |
949 | _int_hash(sz a) { | 953 | _int_hash(sz a) { |
950 | return a * UINT64_C(11400714819323198485); | 954 | return a * UINT64_C(11400714819323198485); |
951 | } | 955 | } |
@@ -1235,14 +1239,6 @@ Allocator os_allocator = { | |||
1235 | .free = platform_free, | 1239 | .free = platform_free, |
1236 | }; | 1240 | }; |
1237 | 1241 | ||
1238 | #include <time.h> | ||
1239 | #include <unistd.h> | ||
1240 | |||
1241 | void | ||
1242 | platform_sleep(size_t microseconds) { | ||
1243 | usleep(microseconds); | ||
1244 | } | ||
1245 | |||
1246 | sz | 1242 | sz |
1247 | platform_time(void) { | 1243 | platform_time(void) { |
1248 | struct timespec ts; | 1244 | struct timespec ts; |
@@ -1504,7 +1500,7 @@ void | |||
1504 | log_func_memory(Logger *l, void *in) { | 1500 | log_func_memory(Logger *l, void *in) { |
1505 | assert(l); | 1501 | assert(l); |
1506 | Array *val = in; | 1502 | Array *val = in; |
1507 | for (sz i = 0; i < MIN(64, val->size); i++) { | 1503 | for (sz i = 0; i < MIN(256, val->size); i++) { |
1508 | Arena scratch = l->storage; | 1504 | Arena scratch = l->storage; |
1509 | log_str(l, str_from_hex(val->mem[i], 2, &scratch)); | 1505 | log_str(l, str_from_hex(val->mem[i], 2, &scratch)); |
1510 | if ((i + 1) % 16 == 0) { | 1506 | if ((i + 1) % 16 == 0) { |