file_posix_darwin.odin 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #+private
  2. package os2
  3. import "base:runtime"
  4. import "core:sys/darwin"
  5. import "core:sys/posix"
  6. _posix_absolute_path :: proc(fd: posix.FD, name: string, allocator: runtime.Allocator) -> (path: cstring, err: Error) {
  7. F_GETPATH :: 50
  8. buf: [posix.PATH_MAX]byte
  9. if posix.fcntl(fd, posix.FCNTL_Cmd(F_GETPATH), &buf) != 0 {
  10. err = _get_platform_error()
  11. return
  12. }
  13. return clone_to_cstring(string(cstring(&buf[0])), allocator)
  14. }
  15. _copy_file_native :: proc(dst_path, src_path: string) -> (err: Error) {
  16. temp_allocator := TEMP_ALLOCATOR_GUARD({})
  17. csrc := clone_to_cstring(src_path, temp_allocator) or_return
  18. cdst := clone_to_cstring(dst_path, temp_allocator) or_return
  19. // Disallow directories, as specified by the generic implementation.
  20. stat: posix.stat_t
  21. if posix.stat(csrc, &stat) != .OK {
  22. err = _get_platform_error()
  23. return
  24. }
  25. if posix.S_ISDIR(stat.st_mode) {
  26. err = .Invalid_File
  27. return
  28. }
  29. ret := darwin.copyfile(csrc, cdst, nil, darwin.COPYFILE_ALL)
  30. if ret < 0 {
  31. err = _get_platform_error()
  32. }
  33. return
  34. }