This commit is contained in:
Daniel Ledda
2025-11-10 03:15:14 +01:00
parent db92620d65
commit a580e7b1cb
6 changed files with 41 additions and 30 deletions

21
core.c
View File

@@ -1,6 +1,6 @@
#include "os.c"
#include "math.h"
#include "string.h" // memmove
#include "string.h" // for memmove
#include "core.h"
#define STB_SPRINTF_IMPLEMENTATION
#include "vendor/stb_sprintf.h"
@@ -165,8 +165,6 @@ string strPrintf(Arena *arena, const char *fmt, ...) {
return result;
}
#define ListSlice(__ls_list__, __ls_start__, __ls_stop__) (__ls_stop__ > l.head || __ls_start__ > __ls_stop__ ? {0} : { l.data + start, stop - start, stop - start, })
string strSlice(string str, size_t start, size_t stop) {
if (stop == 0) {
stop = str.length;
@@ -228,7 +226,7 @@ StringList strSplit(Arena *arena, string splitStr, string inputStr) {
result.data = (string *)beginning;
result.length = splitCount;
result.head = splitCount;
result.capacity = splitCount;
}
return result;
}
@@ -247,14 +245,14 @@ ParsePositiveIntResult parsePositiveInt(string str, size_t *lengthPointer) {
result *= 10;
result += str.str[i] - '0';
}
return (ParsePositiveIntResult){ result, true };
return (ParsePositiveIntResult){ .result=result, .valid=true };
} else {
return (ParsePositiveIntResult){0, false};
return (ParsePositiveIntResult){ .result=0, .valid=false};
}
}
ParsePositiveReal32Result parsePositiveReal32(string str, size_t *lengthPointer) {
ParsePositiveReal32Result result = {NAN, false};
ParsePositiveReal32Result result = { .result=NAN, .valid=false};
string wholePartStr = (string){0};
string fractionalPartStr = (string){0};
@@ -307,9 +305,8 @@ UnixTimestamp getSystemUnixTime() {
}
Timestamp timestampFromUnixTime(UnixTimestamp *unixTimestamp) {
struct tm timestamp = {0};
gmtime_r((time_t *)unixTimestamp, &timestamp);
return timestamp;
struct tm *timestamp = gmtime((time_t *)unixTimestamp);
return *timestamp;
}
string formatTimeHmsUnix(Arena *arena, UnixTimestamp time) {
@@ -406,7 +403,7 @@ void printIntList(IntList l) {
}
print("%i", l.data[i]);
}
print(" } length: %zu, head: %zu\n", l.length, l.head);
print(" } length: %zu, capacity: %zu\n", l.length, l.capacity);
}
void printStrList(StringList l) {
@@ -417,7 +414,7 @@ void printStrList(StringList l) {
}
print("\"%S\"", l.data[i]);
}
print(" } length: %zu, head: %zu\n", l.length, l.head);
print(" } length: %zu, capacity: %zu\n", l.length, l.capacity);
}
int intCompare(const void *a, const void *b) {