mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 04:50:29 +00:00
Add optional truncate parameter to write_entire_file (#144)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user