Skip to content

Commit 7216698

Browse files
dschoGit for Windows Build Agent
authored andcommitted
amend??? mingw: make the dirent implementation pluggable
mingw: make the dirent implementation pluggable Emulating the POSIX `dirent` API on Windows via `FindFirstFile()`/`FindNextFile()` is pretty staightforward, however, most of the information provided in the `WIN32_FIND_DATA` structure is thrown away in the process. A more sophisticated implementation may cache this data, e.g. for later reuse in calls to `lstat()`. Make the `dirent` implementation pluggable so that it can be switched at runtime, e.g. based on a config option. Define a base DIR structure with pointers to `readdir()`/`closedir()` that match the `opendir()` implementation (similar to vtable pointers in Object-Oriented Programming). Define `readdir()`/`closedir()` so that they call the function pointers in the `DIR` structure. This allows to choose the `opendir()` implementation on a call-by-call basis. Make the fixed-size `dirent.d_name` buffer a flex array, as `d_name` may be implementation specific (e.g. a caching implementation may allocate a `struct dirent` with _just_ the size needed to hold the `d_name` in question). Note that we cannot use the `FLEX_ARRAY` macro here because it is defined much later in `git-compat-util.h` than `dirent.h` is (transitively) `#include`d. Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 25a558c commit 7216698

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

compat/win32/dirent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
struct dirent {
1010
unsigned char d_type; /* file type to prevent lstat after readdir */
11-
char d_name[FLEX_ARRAY]; /* file name */
11+
char d_name[/* FLEX_ARRAY */]; /* file name */
1212
};
1313

1414
/*

0 commit comments

Comments
 (0)