os file IO fixes linux
This commit is contained in:
4
os.h
4
os.h
@@ -11,8 +11,8 @@ void os_free(void *ptr, uint64 freeSize);
|
|||||||
|
|
||||||
// ### File IO ###
|
// ### File IO ###
|
||||||
string os_readEntireFile(Arena *arena, string filename);
|
string os_readEntireFile(Arena *arena, string filename);
|
||||||
bool os_writeEntireFile(Arena *arena, string filename, const byte *contents, uint64 contentsLength);
|
bool os_writeEntireFile(string filename, const byte *contents, uint64 contentsLength);
|
||||||
bool os_fileAppend(Arena *arena, string filename, const byte *contents, uint64 contentsLength);
|
bool os_fileAppend(string filename, const byte *contents, uint64 contentsLength);
|
||||||
|
|
||||||
// ### Standard IO ###
|
// ### Standard IO ###
|
||||||
void os_print(StdStream target, const char *fmt, va_list argList);
|
void os_print(StdStream target, const char *fmt, va_list argList);
|
||||||
|
|||||||
20
os_linux.c
20
os_linux.c
@@ -46,7 +46,7 @@ string os_readEntireFile(Arena *arena, string filename) {
|
|||||||
close(input);
|
close(input);
|
||||||
if (bytesRead == -1) {
|
if (bytesRead == -1) {
|
||||||
arenaPopTo(arena, readBuffer.str);
|
arenaPopTo(arena, readBuffer.str);
|
||||||
return s("");
|
readBuffer = s("");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
readBuffer = s("");
|
readBuffer = s("");
|
||||||
@@ -56,35 +56,37 @@ string os_readEntireFile(Arena *arena, string filename) {
|
|||||||
return readBuffer;
|
return readBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool os_writeEntireFile(Arena *arena, string filename, const byte *contents, uint64 contentsLength) {
|
bool os_writeEntireFile(string filename, const byte *contents, uint64 contentsLength) {
|
||||||
Scratch temp = scratchStart(&arena, 1);
|
Scratch temp = scratchStart(NULL, 0);
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
int output = open(cstring(temp.arena, filename), O_WRONLY);
|
struct stat st;
|
||||||
|
stat((char *)filename.str, &st);
|
||||||
|
int output = open(cstring(temp.arena, filename), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
|
||||||
if (output) {
|
if (output) {
|
||||||
int64 bytesWritten = write(output, contents, contentsLength);
|
int64 bytesWritten = write(output, contents, contentsLength);
|
||||||
if (bytesWritten != -1) {
|
if (bytesWritten != -1) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
close(output);
|
|
||||||
}
|
}
|
||||||
|
close(output);
|
||||||
|
|
||||||
scratchEnd(temp);
|
scratchEnd(temp);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool os_fileAppend(Arena *arena, string filename, const byte *contents, uint64 contentsLength) {
|
bool os_fileAppend(string filename, const byte *contents, uint64 contentsLength) {
|
||||||
Scratch temp = scratchStart(&arena, 1);
|
Scratch temp = scratchStart(NULL, 0);
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
int output = open(cstring(temp.arena, filename), O_APPEND);
|
int output = open(cstring(temp.arena, filename), O_WRONLY | O_APPEND);
|
||||||
if (output) {
|
if (output) {
|
||||||
int bytesWritten = write(output, contents, contentsLength);
|
int bytesWritten = write(output, contents, contentsLength);
|
||||||
if (bytesWritten != -1) {
|
if (bytesWritten != -1) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
close(output);
|
|
||||||
}
|
}
|
||||||
|
close(output);
|
||||||
|
|
||||||
scratchEnd(temp);
|
scratchEnd(temp);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user