浏览代码

Add POSIX dirent struct for Linux.

Isaac Andrade 1 年之前
父节点
当前提交
90aa7dff04
共有 4 个文件被更改,包括 30 次插入1 次删除
  1. 3 0
      core/os/os_linux.odin
  2. 21 1
      core/sys/posix/dirent.odin
  3. 3 0
      core/sys/posix/fcntl.odin
  4. 3 0
      core/sys/posix/sys_stat.odin

+ 3 - 0
core/os/os_linux.odin

@@ -26,6 +26,9 @@ Pid       :: distinct i32
 File_Time :: distinct u64
 Socket    :: distinct int
 
+ino_t :: u64
+ino_t32 :: u32
+
 INVALID_HANDLE :: ~Handle(0)
 
 _Platform_Error :: linux.Errno

+ 21 - 1
core/sys/posix/dirent.odin

@@ -202,7 +202,27 @@ when ODIN_OS == .Darwin {
 
 } else when ODIN_OS == .Linux {
 
-	dirent :: struct {
+	when ODIN_ARCH == .i386 || ODIN_ARCH == .wasm32 || ODIN_ARCH == .arm32 {
+
+		dirent :: struct {
+			d_ino: ino_t32,                   /* [PSX] file number of entry */
+			d_off: off_t32,                   /* directory offset of the next entry */
+			d_reclen: c.uint16_t,           /* length of this record */
+			d_type: D_Type,                 /* file type  */
+			d_name: [256]c.char `fmt:"s,0"` /* [PSX] entry name */
+		}
+	} else when ODIN_ARCH == .amd64 || ODIN_ARCH == .wasm64p32 || ODIN_ARCH == .arm64 {
+
+		dirent :: struct {
+			d_ino: ino_t,                   /* [PSX] file number of entry */
+			d_off: off_t,                   /* directory offset of the next entry */
+			d_reclen: c.uint16_t,           /* length of this record */
+			d_type: D_Type,                 /* file type  */
+			d_name: [256]c.char `fmt:"s,0"` /* [PSX] entry name */
+		}
+	}
+
+	dirent64 :: struct {
 		d_ino: ino_t,                   /* [PSX] file number of entry */
 		d_off: off_t,                   /* directory offset of the next entry */
 		d_reclen: c.uint16_t,           /* length of this record */

+ 3 - 0
core/sys/posix/fcntl.odin

@@ -410,6 +410,9 @@ when ODIN_OS == .Darwin {
 		l_whence: c.short,   /* [PSX] flag (Whence) of starting offset */
 	}
 
+} else when ODIN_OS == .Linux {
+	off_t :: distinct c.uint64_t
+	off_t32 :: distinct c.uint32_t
 } else {
 	#panic("posix is unimplemented for the current target")
 }

+ 3 - 0
core/sys/posix/sys_stat.odin

@@ -427,6 +427,9 @@ when ODIN_OS == .Darwin {
 	UTIME_NOW  :: -2
 	UTIME_OMIT :: -1
 
+} when ODIN_OS == .Linux {
+	ino_t :: distinct c.unit64_t
+	ino_t32 :: distinct c.unit32_t
 } else {
 	#panic("posix is unimplemented for the current target")
 }