Skip to content
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

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

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
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
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