dumb fixes
This commit is contained in:
@@ -23,7 +23,9 @@ void os_free(void *ptr, size_t size) {
|
||||
}
|
||||
|
||||
string os_readEntireFile(Arena *arena, string filename) {
|
||||
FILE *input = fopen((char *)filename.str, "r");
|
||||
Scratch temp = scratchStart(&arena, 1);
|
||||
|
||||
FILE *input = fopen(cstring(temp.arena, filename), "r");
|
||||
string readBuffer;
|
||||
if (input) {
|
||||
struct stat st;
|
||||
@@ -35,34 +37,45 @@ string os_readEntireFile(Arena *arena, string filename) {
|
||||
} else {
|
||||
readBuffer = PushString(arena, 0);
|
||||
}
|
||||
|
||||
scratchEnd(temp);
|
||||
return readBuffer;
|
||||
}
|
||||
|
||||
bool os_writeEntireFile(Arena *arena, string filename, const byte *contents, size_t contentsLength) {
|
||||
bool result = false;
|
||||
FILE *output = fopen((char *)filename.str, "w");
|
||||
if (output) {
|
||||
fwrite(contents, contentsLength, contentsLength, output);
|
||||
fclose(output);
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Scratch temp = scratchStart(&arena, 1);
|
||||
|
||||
bool os_fileAppend(Arena *arena, string filename, const byte *contents, size_t contentsLength) {
|
||||
bool result = false;
|
||||
FILE *output = fopen((char *)filename.str, "a");
|
||||
FILE *output = fopen(cstring(temp.arena, filename), "w");
|
||||
if (output) {
|
||||
fwrite(contents, sizeof(byte), contentsLength, output);
|
||||
fclose(output);
|
||||
result = true;
|
||||
}
|
||||
|
||||
scratchEnd(temp);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool os_fileAppend(Arena *arena, string filename, const byte *contents, size_t contentsLength) {
|
||||
Scratch temp = scratchStart(&arena, 1);
|
||||
|
||||
bool result = false;
|
||||
FILE *output = fopen(cstring(temp.arena, filename), "a");
|
||||
if (output) {
|
||||
fwrite(contents, sizeof(byte), contentsLength, output);
|
||||
fclose(output);
|
||||
result = true;
|
||||
}
|
||||
|
||||
scratchEnd(temp);
|
||||
return result;
|
||||
}
|
||||
|
||||
void os_log(LogTarget target, const char *fmt, va_list argList) {
|
||||
Scratch scratch = scratchStart(0, 0);
|
||||
string result = strPrintfv(scratch.arena, fmt, argList);
|
||||
Scratch temp = scratchStart(0, 0);
|
||||
|
||||
string result = strPrintfv(temp.arena, fmt, argList);
|
||||
// TODO(djledda): finish implementation without cstdlib
|
||||
switch (target) {
|
||||
case LogTarget_stdin:
|
||||
@@ -78,7 +91,8 @@ void os_log(LogTarget target, const char *fmt, va_list argList) {
|
||||
write(1, (const void *)result.str, result.length);
|
||||
break;
|
||||
}
|
||||
scratchEnd(scratch);
|
||||
|
||||
scratchEnd(temp);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user