Skip to content

Commit

Permalink
Win32: make the lstat implementation pluggable
Browse files Browse the repository at this point in the history
Emulating the POSIX lstat API on Windows via GetFileAttributes[Ex] is quite
slow. Windows operating system APIs seem to be much better at scanning the
status of entire directories than checking single files. A caching
implementation may improve performance by bulk-reading entire directories
or reusing data obtained via opendir / readdir.

Make the lstat implementation pluggable so that it can be switched at
runtime, e.g. based on a config option.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
kblees authored and dscho committed Sep 18, 2024
1 parent dc626be commit cc74000
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,8 @@ static int do_stat_internal(int follow, const char *file_name, struct stat *buf)
return do_lstat(follow, alt_name, buf);
}

int (*lstat)(const char *file_name, struct stat *buf) = mingw_lstat;

static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
{
BY_HANDLE_FILE_INFORMATION fdata;
Expand Down
2 changes: 1 addition & 1 deletion compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ int mingw_fstat(int fd, struct stat *buf);
#ifdef lstat
#undef lstat
#endif
#define lstat mingw_lstat
extern int (*lstat)(const char *file_name, struct stat *buf);


int mingw_utime(const char *file_name, const struct utimbuf *times);
Expand Down

0 comments on commit cc74000

Please sign in to comment.