From cfaed9d7618ebc83430532f3b16aeb15e02485ab Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Mon, 12 Aug 2019 11:40:32 +0300 Subject: [PATCH] mdbx-chk: don't use internal mdbx_filesize(). Change-Id: I539b92f345ba7884629b702b2568ca805466be3a --- src/tools/mdbx_chk.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/tools/mdbx_chk.c b/src/tools/mdbx_chk.c index e60620db..76ffe1ab 100644 --- a/src/tools/mdbx_chk.c +++ b/src/tools/mdbx_chk.c @@ -1080,7 +1080,25 @@ int main(int argc, char *argv[]) { } uint64_t dxb_filesize = 0; - rc = mdbx_filesize(dxb_fd, &dxb_filesize); +#if defined(_WIN32) || defined(_WIN64) + { + BY_HANDLE_FILE_INFORMATION info; + if (!GetFileInformationByHandle(dxb_fd, &info)) + rc = GetLastError(); + else + dxb_filesize = info.nFileSizeLow | (uint64_t)info.nFileSizeHigh << 32; + } +#else + { + struct stat st; + STATIC_ASSERT_MSG(sizeof(off_t) <= sizeof(uint64_t), + "libmdbx requires 64-bit file I/O on 64-bit systems"); + if (fstat(dxb_fd, &st)) + rc = errno; + else + dxb_filesize = st.st_size; + } +#endif if (rc) { error("mdbx_filesize failed, error %d %s\n", rc, mdbx_strerror(rc)); goto bailout;