mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
os2: better copy_directory, and add native copy_file and copy_directory variants on MacOS
This commit is contained in:
@@ -3,6 +3,7 @@ package os2
|
||||
|
||||
import "base:runtime"
|
||||
|
||||
import "core:sys/darwin"
|
||||
import "core:sys/posix"
|
||||
|
||||
_posix_absolute_path :: proc(fd: posix.FD, name: string, allocator: runtime.Allocator) -> (path: cstring, err: Error) {
|
||||
@@ -16,3 +17,30 @@ _posix_absolute_path :: proc(fd: posix.FD, name: string, allocator: runtime.Allo
|
||||
|
||||
return clone_to_cstring(string(cstring(&buf[0])), allocator)
|
||||
}
|
||||
|
||||
_copy_file_native :: proc(dst_path, src_path: string) -> (err: Error) {
|
||||
temp_allocator := TEMP_ALLOCATOR_GUARD({})
|
||||
|
||||
csrc := clone_to_cstring(src_path, temp_allocator) or_return
|
||||
cdst := clone_to_cstring(dst_path, temp_allocator) or_return
|
||||
|
||||
// Disallow directories, as specified by the generic implementation.
|
||||
|
||||
stat: posix.stat_t
|
||||
if posix.stat(csrc, &stat) != .OK {
|
||||
err = _get_platform_error()
|
||||
return
|
||||
}
|
||||
|
||||
if posix.S_ISDIR(stat.st_mode) {
|
||||
err = .Invalid_File
|
||||
return
|
||||
}
|
||||
|
||||
ret := darwin.copyfile(csrc, cdst, nil, darwin.COPYFILE_ALL)
|
||||
if ret < 0 {
|
||||
err = _get_platform_error()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user