mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Add optional truncate parameter to write_entire_file (#144)
This commit is contained in:
+6
-2
@@ -37,8 +37,12 @@ read_entire_file :: proc(name: string) -> (data: []u8, success: bool) {
|
|||||||
return data[0..bytes_read], true;
|
return data[0..bytes_read], true;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_entire_file :: proc(name: string, data: []u8) -> (success: bool) {
|
write_entire_file :: proc(name: string, data: []u8, truncate := true) -> (success: bool) {
|
||||||
fd, err := open(name, O_WRONLY|O_CREATE, 0);
|
flags: int = O_WRONLY|O_CREATE;
|
||||||
|
if truncate {
|
||||||
|
flags |= O_TRUNC;
|
||||||
|
}
|
||||||
|
fd, err := open(name, flags, 0);
|
||||||
if err != 0 {
|
if err != 0 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user