aboutsummaryrefslogtreecommitdiff
path: root/core/sys
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2024-11-15 23:22:14 +0000
committerGitHub <noreply@github.com>2024-11-15 23:22:14 +0000
commit0781871efdcfeda13d3d8d51df62b5e578da774a (patch)
treee2dbc6d373b11aa9650f41aa864644cebf50b05c /core/sys
parenta3442b22da2cc4adbd52327d99d47e79c7e3a7bb (diff)
parent282d956aa7c9e0a59a94b6e5091c369f491d38f7 (diff)
Merge pull request #4489 from laytan/os2-dir-leak-and-test
os2: fix leak in dir_windows, fix netbsd, and add a test for dir reading
Diffstat (limited to 'core/sys')
-rw-r--r--core/sys/posix/dirent.odin34
1 files 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
@@ -55,15 +55,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.
The file offset associated with the file descriptor at the time of the call determines
@@ -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 {