file.odin 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package os2
  2. import "core:io"
  3. import "core:time"
  4. Handle :: distinct uintptr
  5. Seek_From :: enum {
  6. Start = 0, // seek relative to the origin of the file
  7. Current = 1, // seek relative to the current offset
  8. End = 2, // seek relative to the end
  9. }
  10. File_Mode :: distinct u32
  11. File_Mode_Dir :: File_Mode(1<<16)
  12. File_Mode_Named_Pipe :: File_Mode(1<<17)
  13. File_Mode_Device :: File_Mode(1<<18)
  14. File_Mode_Char_Device :: File_Mode(1<<19)
  15. File_Mode_Sym_Link :: File_Mode(1<<20)
  16. O_RDONLY :: int( 0)
  17. O_WRONLY :: int( 1)
  18. O_RDWR :: int( 2)
  19. O_APPEND :: int( 4)
  20. O_CREATE :: int( 8)
  21. O_EXCL :: int(16)
  22. O_SYNC :: int(32)
  23. O_TRUNC :: int(64)
  24. stdin: Handle = 0 // OS-Specific
  25. stdout: Handle = 1 // OS-Specific
  26. stderr: Handle = 2 // OS-Specific
  27. create :: proc(name: string) -> (Handle, Error) {
  28. return _create(name)
  29. }
  30. open :: proc(name: string) -> (Handle, Error) {
  31. return _open(name)
  32. }
  33. open_file :: proc(name: string, flag: int, perm: File_Mode) -> (Handle, Error) {
  34. return _open_file(name, flag, perm)
  35. }
  36. close :: proc(fd: Handle) -> Error {
  37. return _close(fd)
  38. }
  39. name :: proc(fd: Handle, allocator := context.allocator) -> string {
  40. return _name(fd)
  41. }
  42. seek :: proc(fd: Handle, offset: i64, whence: Seek_From) -> (ret: i64, err: Error) {
  43. return _seek(fd, offset, whence)
  44. }
  45. read :: proc(fd: Handle, p: []byte) -> (n: int, err: Error) {
  46. return _read(fd, p)
  47. }
  48. read_at :: proc(fd: Handle, p: []byte, offset: i64) -> (n: int, err: Error) {
  49. return _read_at(fd, p, offset)
  50. }
  51. read_from :: proc(fd: Handle, r: io.Reader) -> (n: i64, err: Error) {
  52. return _read_from(fd, r)
  53. }
  54. write :: proc(fd: Handle, p: []byte) -> (n: int, err: Error) {
  55. return _write(fd, p)
  56. }
  57. write_at :: proc(fd: Handle, p: []byte, offset: i64) -> (n: int, err: Error) {
  58. return _write_at(fd, p, offset)
  59. }
  60. write_to :: proc(fd: Handle, w: io.Writer) -> (n: i64, err: Error) {
  61. return _write_to(fd, w)
  62. }
  63. file_size :: proc(fd: Handle) -> (n: i64, err: Error) {
  64. return _file_size(fd)
  65. }
  66. sync :: proc(fd: Handle) -> Error {
  67. return _sync(fd)
  68. }
  69. flush :: proc(fd: Handle) -> Error {
  70. return _flush(fd)
  71. }
  72. truncate :: proc(fd: Handle, size: i64) -> Maybe(Path_Error) {
  73. return _truncate(fd, size)
  74. }
  75. remove :: proc(name: string) -> Maybe(Path_Error) {
  76. return _remove(name)
  77. }
  78. rename :: proc(old_path, new_path: string) -> Maybe(Path_Error) {
  79. return _rename(old_path, new_path)
  80. }
  81. link :: proc(old_name, new_name: string) -> Maybe(Link_Error) {
  82. return _link(old_name, new_name)
  83. }
  84. symlink :: proc(old_name, new_name: string) -> Maybe(Link_Error) {
  85. return _symlink(old_name, new_name)
  86. }
  87. read_link :: proc(name: string) -> (string, Maybe(Path_Error)) {
  88. return _read_link(name)
  89. }
  90. chdir :: proc(fd: Handle) -> Error {
  91. return _chdir(fd)
  92. }
  93. chmod :: proc(fd: Handle, mode: File_Mode) -> Error {
  94. return _chmod(fd, mode)
  95. }
  96. chown :: proc(fd: Handle, uid, gid: int) -> Error {
  97. return _chown(fd, uid, gid)
  98. }
  99. lchown :: proc(name: string, uid, gid: int) -> Error {
  100. return _lchown(name, uid, gid)
  101. }
  102. chtimes :: proc(name: string, atime, mtime: time.Time) -> Maybe(Path_Error) {
  103. return _chtimes(name, atime, mtime)
  104. }
  105. exists :: proc(path: string) -> bool {
  106. return _exists(path)
  107. }
  108. is_file :: proc(path: string) -> bool {
  109. return _is_file(path)
  110. }
  111. is_dir :: proc(path: string) -> bool {
  112. return _is_dir(path)
  113. }