feat: Implement dirent API for Windows using WinAPI
This commit introduces a complete implementation of the POSIX
dirent API for Windows, enabling C/C++ code to interact with
directories in a platform-independent manner. The implementation
leverages the Windows API for core functionality.
The following functions are implemented:
- opendir: Opens a directory stream.
- readdir: Reads a directory entry.
- closedir: Closes a directory stream.
- rewinddir: Resets a directory stream to the beginning.
- telldir: Gets the current position of a directory stream.
- seekdir: Sets the position of a directory stream.
Key Features:
- Supports UTF-8 encoded filenames.
- Handles extended-length paths using the \\?\ prefix.
- Uses std::unique_ptr for internal memory management.
- Provides comprehensive error handling via errno.
Limitations:
- telldir and seekdir have limited functionality due to the
underlying Windows API. seekdir is O(N) for non-zero
positive positions.
- Thread safety is not yet implemented.
This implementation provides a robust and portable way to work
with directories on Windows, bridging the gap between POSIX
and Windows file system APIs.
This will make sure that qemu will properly handle utf-8 when using
dirent.
Change-Id: I9462e32b1ee7f6133a698d7200eed74ea2b82a37
GitOrigin-RevId: 97208f534483e2f68b832bda47887b8b6addd955
5 files changed