Add optional truncate parameter to write_entire_file (#144)

This commit is contained in:
gingerBill
2017-11-13 20:35:21 +00:00
parent f6a56c2f82
commit a137699d95

View File

@@ -37,8 +37,12 @@ read_entire_file :: proc(name: string) -> (data: []u8, success: bool) {
return data[0..bytes_read], true;
}
write_entire_file :: proc(name: string, data: []u8) -> (success: bool) {
fd, err := open(name, O_WRONLY|O_CREATE, 0);
write_entire_file :: proc(name: string, data: []u8, truncate := true) -> (success: bool) {
flags: int = O_WRONLY|O_CREATE;
if truncate {
flags |= O_TRUNC;
}
fd, err := open(name, flags, 0);
if err != 0 {
return false;
}