aboutsummaryrefslogtreecommitdiff
path: root/win32/mingw.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-01-17 14:42:42 +0000
committerRon Yorston <rmy@pobox.com>2023-01-17 14:42:42 +0000
commitdbd187697d1265d345e3e3e8b302a88b04592cc2 (patch)
tree5b9983ad607193c06c7862a80bba1f83ec46be12 /win32/mingw.c
parent88965fe20a26e17247e6ffc10692fe202d77f1fa (diff)
downloadbusybox-w32-dbd187697d1265d345e3e3e8b302a88b04592cc2.tar.gz
busybox-w32-dbd187697d1265d345e3e3e8b302a88b04592cc2.tar.bz2
busybox-w32-dbd187697d1265d345e3e3e8b302a88b04592cc2.zip
win32: minor improvements to stat(2)
Commit b11352dcb (win32: prevent stat(2) from updating access times) requested GENERIC_ALL access when opening files. It appears that GENERIC_READ is sufficient and also faster. The code to find the actual size of compressed or sparse files only needs to be invoked for regular files. Avoiding unnecessary calls to GetCompressedFileSize() makes stat(2) slightly faster and gives a more accurate number of blocks for symbolic links.
Diffstat (limited to '')
-rw-r--r--win32/mingw.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index bfc1531fb..847e7f6a5 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -444,7 +444,7 @@ static int has_exec_format(const char *name)
444 return 0; 444 return 0;
445 445
446 /* Open file and try to avoid updating access time */ 446 /* Open file and try to avoid updating access time */
447 fh = CreateFileA(name, GENERIC_ALL, 0, NULL, OPEN_EXISTING, 0, NULL); 447 fh = CreateFileA(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
448 if (fh != INVALID_HANDLE_VALUE) { 448 if (fh != INVALID_HANDLE_VALUE) {
449 FILETIME last_access = { 0xffffffff, 0xffffffff }; 449 FILETIME last_access = { 0xffffffff, 0xffffffff };
450 450
@@ -725,14 +725,14 @@ static int do_lstat(int follow, const char *file_name, struct mingw_stat *buf)
725 } 725 }
726#endif 726#endif
727 727
728 /* Get actual size of compressed/sparse files */ 728 /* Get actual size of compressed/sparse files. Only regular
729 low = GetCompressedFileSize(file_name, &high); 729 * files need to be considered. */
730 if ((low == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) || 730 size = buf->st_size;
731 (buf->st_attr & FILE_ATTRIBUTE_DIRECTORY)) { 731 if (S_ISREG(buf->st_mode)) {
732 size = buf->st_size; 732 low = GetCompressedFileSize(file_name, &high);
733 } 733 if (low != INVALID_FILE_SIZE || GetLastError() == NO_ERROR) {
734 else { 734 size = low | (((off64_t)high)<<32);
735 size = low | (((off64_t)high)<<32); 735 }
736 } 736 }
737 737
738 /* 738 /*