summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2019-11-18 10:40:47 +0000
committerFrediano Ziglio <fziglio@redhat.com>2019-11-21 14:48:32 +0000
commit615cd463e01750ac24efd58ab5f709181cfa6a67 (patch)
treee5977e173bdaf4583bc5d915129e824a59bff848
parent1dd3f3586a4f3dfb35d2ec1ddbec0c25c4126c86 (diff)
vdlog: Use _wstat64 instead of GetFileSize
This has different advantages: - code is shorter and more readable; - does not need to open the file and close; - works on files bigger than 4gb. Signed-off-by: Frediano Ziglio <fziglio@redhat.com> Acked-by: Victor Toso <victortoso@redhat.com>
-rw-r--r--common/vdlog.cpp10
1 files changed, 2 insertions, 8 deletions
diff --git a/common/vdlog.cpp b/common/vdlog.cpp
index e2561e2..a484a07 100644
--- a/common/vdlog.cpp
+++ b/common/vdlog.cpp
@@ -46,14 +46,8 @@ VDLog* VDLog::get(TCHAR* path)
if (_log || !path) {
return _log;
}
- DWORD size = 0;
- HANDLE file = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
- NULL);
- if (file != INVALID_HANDLE_VALUE) {
- size = GetFileSize(file, NULL);
- CloseHandle(file);
- }
- if (size != INVALID_FILE_SIZE && size > LOG_ROLL_SIZE) {
+ __stat64 buf;
+ if (_wstat64(path, &buf) == 0 && buf.st_size > LOG_ROLL_SIZE) {
TCHAR roll_path[MAX_PATH];
swprintf_s(roll_path, MAX_PATH, L"%s.1", path);
if (!MoveFileEx(path, roll_path, MOVEFILE_REPLACE_EXISTING)) {