Browse Source

Merge pull request #517 from SSStormy/fix-os-linux-fs-stuffs

Unix: Fix improper _unix_open binding; make write_entire_file set sane file permissions.
gingerBill 5 years ago
parent
commit
fb0fb4767b
2 changed files with 9 additions and 2 deletions
  1. 8 1
      core/os/os.odin
  2. 1 1
      core/os/os_linux.odin

+ 8 - 1
core/os/os.odin

@@ -99,7 +99,14 @@ write_entire_file :: proc(name: string, data: []byte, truncate := true) -> (succ
 	if truncate {
 	if truncate {
 		flags |= O_TRUNC;
 		flags |= O_TRUNC;
 	}
 	}
-	fd, err := open(name, flags, 0);
+
+    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 {
 	if err != 0 {
 		return false;
 		return false;
 	}
 	}

+ 1 - 1
core/os/os_linux.odin

@@ -259,7 +259,7 @@ foreign libc {
 	@(link_name="__errno_location") __errno_location    :: proc() -> ^int ---;
 	@(link_name="__errno_location") __errno_location    :: proc() -> ^int ---;
 	@(link_name="syscall")          syscall             :: proc(number: Syscall, #c_vararg args: ..any) -> int ---;
 	@(link_name="syscall")          syscall             :: proc(number: Syscall, #c_vararg args: ..any) -> int ---;
 
 
-	@(link_name="open")             _unix_open          :: proc(path: cstring, flags: int, #c_vararg mode: ..any) -> Handle ---;
+	@(link_name="open")             _unix_open          :: proc(path: cstring, flags: int, mode: int) -> Handle ---;
 	@(link_name="close")            _unix_close         :: proc(fd: Handle) -> int ---;
 	@(link_name="close")            _unix_close         :: proc(fd: Handle) -> int ---;
 	@(link_name="read")             _unix_read          :: proc(fd: Handle, buf: rawptr, size: int) -> int ---;
 	@(link_name="read")             _unix_read          :: proc(fd: Handle, buf: rawptr, size: int) -> int ---;
 	@(link_name="write")            _unix_write         :: proc(fd: Handle, buf: rawptr, size: int) -> int ---;
 	@(link_name="write")            _unix_write         :: proc(fd: Handle, buf: rawptr, size: int) -> int ---;