Browse Source

Add optional truncate parameter to write_entire_file (#144)

gingerBill 7 years ago
parent
commit
a137699d95
1 changed files with 6 additions and 2 deletions
  1. 6 2
      core/os.odin

+ 6 - 2
core/os.odin

@@ -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) {
-	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 {
 	if err != 0 {
 		return false;
 		return false;
 	}
 	}