mirror of https://github.com/decompals/wibo.git
kernel32: Use fstat in GetFileSize (#10)
Improves mwldeppc performance significantly. Before: real 0m30.322s user 0m7.800s sys 0m22.495s After: real 0m16.679s user 0m4.693s sys 0m11.965s Wine (for comparison): real 0m24.625s user 0m0.048s sys 0m0.034s
This commit is contained in:
parent
07af846d1c
commit
a8b9452f33
22
kernel32.cpp
22
kernel32.cpp
|
@ -7,6 +7,7 @@
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
namespace kernel32 {
|
namespace kernel32 {
|
||||||
|
|
||||||
|
@ -442,19 +443,18 @@ namespace kernel32 {
|
||||||
*/
|
*/
|
||||||
unsigned int WIN_FUNC GetFileSize(void *hFile, unsigned int *lpFileSizeHigh) {
|
unsigned int WIN_FUNC GetFileSize(void *hFile, unsigned int *lpFileSizeHigh) {
|
||||||
DEBUG_LOG("GetFileSize\n");
|
DEBUG_LOG("GetFileSize\n");
|
||||||
|
struct stat64 st;
|
||||||
FILE *fp = files::fpFromHandle(hFile);
|
FILE *fp = files::fpFromHandle(hFile);
|
||||||
long pos = ftell(fp);
|
fflush(fp);
|
||||||
assert(pos >= 0);
|
if (fstat64(fileno(fp), &st) == -1 || !S_ISREG(st.st_mode)) {
|
||||||
int r = fseek(fp, 0L, SEEK_END);
|
wibo::lastError = 2; // ERROR_FILE_NOT_FOUND (?)
|
||||||
assert(r == 0);
|
return ~0u; // INVALID_FILE_SIZE
|
||||||
long sz = ftell(fp);
|
|
||||||
assert(sz >= 0);
|
|
||||||
fseek(fp, pos, SEEK_SET);
|
|
||||||
if (lpFileSizeHigh) {
|
|
||||||
*lpFileSizeHigh = 0;
|
|
||||||
}
|
}
|
||||||
DEBUG_LOG("-> %d\n", (int)sz);
|
DEBUG_LOG("-> %ld\n", st.st_size);
|
||||||
return (unsigned int)sz;
|
if (lpFileSizeHigh != nullptr) {
|
||||||
|
*lpFileSizeHigh = st.st_size >> 32;
|
||||||
|
}
|
||||||
|
return st.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FILETIME {
|
struct FILETIME {
|
||||||
|
|
Loading…
Reference in New Issue