Skip to content

[wasm] Port use of dirent for wasi-libc #4892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,10 @@ static inline int _direntNameLength(struct dirent *entry) {
#endif
}

static inline char *_direntName(struct dirent *entry) {
return entry->d_name;
}

// major() and minor() might be implemented as macros or functions.
static inline unsigned int _dev_major(dev_t rdev) {
return major(rdev);
Expand Down
6 changes: 2 additions & 4 deletions Sources/Foundation/FileManager+POSIX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,8 @@ extension FileManager {
errno = 0
while let entry = readdir(dir) {
let length = Int(_direntNameLength(entry))
let entryName = withUnsafePointer(to: entry.pointee.d_name) { (ptr) -> String in
let namePtr = UnsafeRawPointer(ptr).assumingMemoryBound(to: CChar.self)
return string(withFileSystemRepresentation: namePtr, length: length)
}
let namePtr = UnsafeRawPointer(_direntName(entry)).assumingMemoryBound(to: CChar.self)
let entryName = string(withFileSystemRepresentation: namePtr, length: length)
if entryName != "." && entryName != ".." {
let entryType = Int32(entry.pointee.d_type)
try closure(entryName, entryType)
Expand Down