From d94ef8d27a3c1876b1d755fb223ee898822f0257 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Fri, 15 Nov 2024 21:22:23 +0100 Subject: [PATCH] sys/posix: fix dirfd on netbsd --- core/sys/posix/dirent.odin | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/core/sys/posix/dirent.odin b/core/sys/posix/dirent.odin index 73351b29d..bf32be8cf 100644 --- a/core/sys/posix/dirent.odin +++ b/core/sys/posix/dirent.odin @@ -54,15 +54,6 @@ foreign lib { */ closedir :: proc(dirp: DIR) -> result --- - /* - Return a file descriptor referring to the same directory as the dirp argument. - - // TODO: this is a macro on NetBSD? - - [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html ]] - */ - dirfd :: proc(dirp: DIR) -> FD --- - /* Equivalent to the opendir() function except that the directory is specified by a file descriptor rather than by a name. @@ -161,11 +152,36 @@ when ODIN_OS == .NetBSD { @(private) LSCANDIR :: "__scandir30" @(private) LOPENDIR :: "__opendir30" @(private) LREADDIR :: "__readdir30" + + /* + Return a file descriptor referring to the same directory as the dirp argument. + + [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html ]] + */ + dirfd :: proc "c" (dirp: DIR) -> FD { + _dirdesc :: struct { + dd_fd: FD, + + // more stuff... + } + + return (^_dirdesc)(dirp).dd_fd + } + } else { @(private) LALPHASORT :: "alphasort" + INODE_SUFFIX @(private) LSCANDIR :: "scandir" + INODE_SUFFIX @(private) LOPENDIR :: "opendir" + INODE_SUFFIX @(private) LREADDIR :: "readdir" + INODE_SUFFIX + + foreign lib { + /* + Return a file descriptor referring to the same directory as the dirp argument. + + [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html ]] + */ + dirfd :: proc(dirp: DIR) -> FD --- + } } when ODIN_OS == .Darwin {