Fix os.read / os.read_entire_file

- DWORDs are NOT i32
- os.read didn't correctly read as much as it could
This commit is contained in:
Tetralux
2020-03-12 22:31:00 +00:00
parent e0a370f8f1
commit 1181d7cf90
3 changed files with 24 additions and 26 deletions
+8 -8
View File
@@ -85,13 +85,13 @@ read_entire_file :: proc(name: string) -> (data: []byte, success: bool) {
if data == nil {
return nil, false;
}
defer if !success do delete(data);
bytes_read, read_err := read(fd, data);
if read_err != 0 {
delete(data);
if read_err != ERROR_NONE {
return nil, false;
}
return data[0:bytes_read], true;
return data[:bytes_read], true;
}
write_entire_file :: proc(name: string, data: []byte, truncate := true) -> (success: bool) {
@@ -100,11 +100,11 @@ write_entire_file :: proc(name: string, data: []byte, truncate := true) -> (succ
flags |= O_TRUNC;
}
mode: int = 0;
when OS == "linux" {
// NOTE(justasd): 644 (owner read, write; group read; others read)
mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
}
mode: int = 0;
when OS == "linux" {
// NOTE(justasd): 644 (owner read, write; group read; others read)
mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
}
fd, err := open(name, flags, mode);
if err != 0 {