|
@@ -40,7 +40,7 @@ _file_allocator :: proc() -> runtime.Allocator {
|
|
|
|
|
|
_open :: proc(name: string, flags: File_Flags, perm: File_Mode) -> (^File, Error) {
|
|
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
|
|
- name_cstr := _name_to_cstring(name)
|
|
|
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
|
|
|
|
|
|
flags_i: int
|
|
|
switch flags & O_RDONLY|O_WRONLY|O_RDWR {
|
|
@@ -56,7 +56,7 @@ _open :: proc(name: string, flags: File_Flags, perm: File_Mode) -> (^File, Error
|
|
|
flags_i |= (_O_TRUNC * int(.Trunc in flags))
|
|
|
flags_i |= (_O_CLOEXEC * int(.Close_On_Exec in flags))
|
|
|
|
|
|
- fd := unix.sys_open(name_cstr, flags_i, int(perm))
|
|
|
+ fd := unix.sys_open(name_cstr, flags_i, uint(perm))
|
|
|
if fd < 0 {
|
|
|
return nil, _get_platform_error(fd)
|
|
|
}
|
|
@@ -196,10 +196,7 @@ _truncate :: proc(f: ^File, size: i64) -> Error {
|
|
|
}
|
|
|
|
|
|
_remove :: proc(name: string) -> Error {
|
|
|
- name_cstr, allocated := _name_to_cstring(name)
|
|
|
- defer if allocated {
|
|
|
- delete(name_cstr)
|
|
|
- }
|
|
|
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
|
|
|
|
|
|
fd := unix.sys_open(name_cstr, int(File_Flags.Read))
|
|
|
if fd < 0 {
|
|
@@ -214,40 +211,22 @@ _remove :: proc(name: string) -> Error {
|
|
|
}
|
|
|
|
|
|
_rename :: proc(old_name, new_name: string) -> Error {
|
|
|
- old_name_cstr, old_allocated := _name_to_cstring(old_name)
|
|
|
- new_name_cstr, new_allocated := _name_to_cstring(new_name)
|
|
|
- defer if old_allocated {
|
|
|
- delete(old_name_cstr)
|
|
|
- }
|
|
|
- defer if new_allocated {
|
|
|
- delete(new_name_cstr)
|
|
|
- }
|
|
|
+ old_name_cstr := strings.clone_to_cstring(old_name, context.temp_allocator)
|
|
|
+ new_name_cstr := strings.clone_to_cstring(new_name, context.temp_allocator)
|
|
|
|
|
|
return _ok_or_error(unix.sys_rename(old_name_cstr, new_name_cstr))
|
|
|
}
|
|
|
|
|
|
_link :: proc(old_name, new_name: string) -> Error {
|
|
|
- old_name_cstr, old_allocated := _name_to_cstring(old_name)
|
|
|
- new_name_cstr, new_allocated := _name_to_cstring(new_name)
|
|
|
- defer if old_allocated {
|
|
|
- delete(old_name_cstr)
|
|
|
- }
|
|
|
- defer if new_allocated {
|
|
|
- delete(new_name_cstr)
|
|
|
- }
|
|
|
+ old_name_cstr := strings.clone_to_cstring(old_name, context.temp_allocator)
|
|
|
+ new_name_cstr := strings.clone_to_cstring(new_name, context.temp_allocator)
|
|
|
|
|
|
return _ok_or_error(unix.sys_link(old_name_cstr, new_name_cstr))
|
|
|
}
|
|
|
|
|
|
_symlink :: proc(old_name, new_name: string) -> Error {
|
|
|
- old_name_cstr, old_allocated := _name_to_cstring(old_name)
|
|
|
- new_name_cstr, new_allocated := _name_to_cstring(new_name)
|
|
|
- defer if old_allocated {
|
|
|
- delete(old_name_cstr)
|
|
|
- }
|
|
|
- defer if new_allocated {
|
|
|
- delete(new_name_cstr)
|
|
|
- }
|
|
|
+ old_name_cstr := strings.clone_to_cstring(old_name, context.temp_allocator)
|
|
|
+ new_name_cstr := strings.clone_to_cstring(new_name, context.temp_allocator)
|
|
|
|
|
|
return _ok_or_error(unix.sys_symlink(old_name_cstr, new_name_cstr))
|
|
|
}
|
|
@@ -271,26 +250,17 @@ _read_link_cstr :: proc(name_cstr: cstring, allocator: runtime.Allocator) -> (st
|
|
|
}
|
|
|
|
|
|
_read_link :: proc(name: string, allocator: runtime.Allocator) -> (string, Error) {
|
|
|
- name_cstr, allocated := _name_to_cstring(name)
|
|
|
- defer if allocated {
|
|
|
- delete(name_cstr)
|
|
|
- }
|
|
|
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
|
|
|
return _read_link_cstr(name_cstr, allocator)
|
|
|
}
|
|
|
|
|
|
_unlink :: proc(name: string) -> Error {
|
|
|
- name_cstr, allocated := _name_to_cstring(name)
|
|
|
- defer if allocated {
|
|
|
- delete(name_cstr)
|
|
|
- }
|
|
|
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
|
|
|
return _ok_or_error(unix.sys_unlink(name_cstr))
|
|
|
}
|
|
|
|
|
|
_chdir :: proc(name: string) -> Error {
|
|
|
- name_cstr, allocated := _name_to_cstring(name)
|
|
|
- defer if allocated {
|
|
|
- delete(name_cstr)
|
|
|
- }
|
|
|
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
|
|
|
return _ok_or_error(unix.sys_chdir(name_cstr))
|
|
|
}
|
|
|
|
|
@@ -299,32 +269,23 @@ _fchdir :: proc(f: ^File) -> Error {
|
|
|
}
|
|
|
|
|
|
_chmod :: proc(name: string, mode: File_Mode) -> Error {
|
|
|
- name_cstr, allocated := _name_to_cstring(name)
|
|
|
- defer if allocated {
|
|
|
- delete(name_cstr)
|
|
|
- }
|
|
|
- return _ok_or_error(unix.sys_chmod(name_cstr, int(mode)))
|
|
|
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
|
|
|
+ return _ok_or_error(unix.sys_chmod(name_cstr, uint(mode)))
|
|
|
}
|
|
|
|
|
|
_fchmod :: proc(f: ^File, mode: File_Mode) -> Error {
|
|
|
- return _ok_or_error(unix.sys_fchmod(f.impl.fd, int(mode)))
|
|
|
+ return _ok_or_error(unix.sys_fchmod(f.impl.fd, uint(mode)))
|
|
|
}
|
|
|
|
|
|
// NOTE: will throw error without super user priviledges
|
|
|
_chown :: proc(name: string, uid, gid: int) -> Error {
|
|
|
- name_cstr, allocated := _name_to_cstring(name)
|
|
|
- defer if allocated {
|
|
|
- delete(name_cstr)
|
|
|
- }
|
|
|
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
|
|
|
return _ok_or_error(unix.sys_chown(name_cstr, uid, gid))
|
|
|
}
|
|
|
|
|
|
// NOTE: will throw error without super user priviledges
|
|
|
_lchown :: proc(name: string, uid, gid: int) -> Error {
|
|
|
- name_cstr, allocated := _name_to_cstring(name)
|
|
|
- defer if allocated {
|
|
|
- delete(name_cstr)
|
|
|
- }
|
|
|
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
|
|
|
return _ok_or_error(unix.sys_lchown(name_cstr, uid, gid))
|
|
|
}
|
|
|
|
|
@@ -334,10 +295,7 @@ _fchown :: proc(f: ^File, uid, gid: int) -> Error {
|
|
|
}
|
|
|
|
|
|
_chtimes :: proc(name: string, atime, mtime: time.Time) -> Error {
|
|
|
- name_cstr, allocated := _name_to_cstring(name)
|
|
|
- defer if allocated {
|
|
|
- delete(name_cstr)
|
|
|
- }
|
|
|
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
|
|
|
times := [2]Unix_File_Time {
|
|
|
{ atime._nsec, 0 },
|
|
|
{ mtime._nsec, 0 },
|
|
@@ -354,18 +312,12 @@ _fchtimes :: proc(f: ^File, atime, mtime: time.Time) -> Error {
|
|
|
}
|
|
|
|
|
|
_exists :: proc(name: string) -> bool {
|
|
|
- name_cstr, allocated := _name_to_cstring(name)
|
|
|
- defer if allocated {
|
|
|
- delete(name_cstr)
|
|
|
- }
|
|
|
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
|
|
|
return unix.sys_access(name_cstr, F_OK) == 0
|
|
|
}
|
|
|
|
|
|
_is_file :: proc(name: string) -> bool {
|
|
|
- name_cstr, allocated := _name_to_cstring(name)
|
|
|
- defer if allocated {
|
|
|
- delete(name_cstr)
|
|
|
- }
|
|
|
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
|
|
|
s: _Stat
|
|
|
res := unix.sys_stat(name_cstr, &s)
|
|
|
if res < 0 {
|
|
@@ -384,10 +336,7 @@ _is_file_fd :: proc(fd: int) -> bool {
|
|
|
}
|
|
|
|
|
|
_is_dir :: proc(name: string) -> bool {
|
|
|
- name_cstr, allocated := _name_to_cstring(name)
|
|
|
- defer if allocated {
|
|
|
- delete(name_cstr)
|
|
|
- }
|
|
|
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
|
|
|
s: _Stat
|
|
|
res := unix.sys_stat(name_cstr, &s)
|
|
|
if res < 0 {
|