Skip to content

Commit 3ce002f

Browse files
hychfuru
authored andcommitted
ITS#7959 fix prev commit
fstat returns -1, not an errno. Move code into its own function for reuse.
1 parent ce40f4f commit 3ce002f

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

libraries/liblmdb/mdb.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,6 +3828,27 @@ mdb_env_get_maxreaders(MDB_env *env, unsigned int *readers)
38283828
return MDB_SUCCESS;
38293829
}
38303830

3831+
static int ESECT
3832+
mdb_fsize(HANDLE fd, size_t *size)
3833+
{
3834+
#ifdef WIN32
3835+
LARGE_INTEGER fsize;
3836+
3837+
if (!GetFileSizeEx(fd, &fsize))
3838+
return ErrCode();
3839+
3840+
*size = fsize.QuadPart;
3841+
#else
3842+
struct stat st;
3843+
3844+
if (fstat(fd, &st))
3845+
return ErrCode();
3846+
3847+
*size = st.st_size;
3848+
#endif
3849+
return MDB_SUCCESS;
3850+
}
3851+
38313852
/** Further setup required for opening an LMDB environment
38323853
*/
38333854
static int ESECT
@@ -8690,30 +8711,13 @@ mdb_env_copyfd0(MDB_env *env, HANDLE fd)
86908711
goto leave;
86918712

86928713
w2 = txn->mt_next_pgno * env->me_psize;
8693-
#ifdef WIN32
86948714
{
8695-
LARGE_INTEGER fsize;
8696-
8697-
if (!GetFileSizeEx(env->me_fd, &fsize)) {
8698-
rc = ErrCode();
8715+
size_t fsize = 0;
8716+
if ((rc = mdb_fsize(env->me_fd, &fsize)))
86998717
goto leave;
8700-
}
8701-
8702-
if (w2 > fsize.QuadPart)
8703-
w2 = fsize.QuadPart;
8718+
if (w2 > fsize)
8719+
w2 = fsize;
87048720
}
8705-
#else
8706-
{
8707-
struct stat st;
8708-
8709-
if ((rc = fstat(env->me_fd, &st))) {
8710-
goto leave;
8711-
}
8712-
8713-
if (w2 > (size_t)st.st_size)
8714-
w2 = st.st_size;
8715-
}
8716-
#endif
87178721
wsize = w2 - wsize;
87188722
while (wsize > 0) {
87198723
if (wsize > MAX_WRITE)

0 commit comments

Comments
 (0)