]> git.sur5r.net Git - openldap/commitdiff
ITS#7959 fix prev commit
authorHoward Chu <hyc@symas.com>
Wed, 8 Oct 2014 18:25:27 +0000 (19:25 +0100)
committerHallvard Furuseth <hallvard@openldap.org>
Mon, 1 Dec 2014 19:15:36 +0000 (20:15 +0100)
fstat returns -1, not an errno. Move code into its own function
for reuse.

libraries/liblmdb/mdb.c

index 524dde96d6367e06ed669a9a7c1a0f2e307d88ae..2e9e3dc96e103615517dcb9d003cb642617cc0f6 100644 (file)
@@ -3828,6 +3828,27 @@ mdb_env_get_maxreaders(MDB_env *env, unsigned int *readers)
        return MDB_SUCCESS;
 }
 
+static int ESECT
+mdb_fsize(HANDLE fd, size_t *size)
+{
+#ifdef WIN32
+       LARGE_INTEGER fsize;
+
+       if (!GetFileSizeEx(fd, &fsize))
+               return ErrCode();
+
+       *size = fsize.QuadPart;
+#else
+       struct stat st;
+
+       if (fstat(fd, &st))
+               return ErrCode();
+
+       *size = st.st_size;
+#endif
+       return MDB_SUCCESS;
+}
+
 /** Further setup required for opening an LMDB environment
  */
 static int ESECT
@@ -8690,30 +8711,13 @@ mdb_env_copyfd0(MDB_env *env, HANDLE fd)
                goto leave;
 
        w2 = txn->mt_next_pgno * env->me_psize;
-#ifdef WIN32
        {
-               LARGE_INTEGER fsize;
-
-               if (!GetFileSizeEx(env->me_fd, &fsize)) {
-                       rc = ErrCode();
+               size_t fsize = 0;
+               if ((rc = mdb_fsize(env->me_fd, &fsize)))
                        goto leave;
-               }
-
-               if (w2 > fsize.QuadPart)
-                       w2 = fsize.QuadPart;
+               if (w2 > fsize)
+                       w2 = fsize;
        }
-#else
-       {
-               struct stat st;
-
-               if ((rc = fstat(env->me_fd, &st))) {
-                       goto leave;
-               }
-
-               if (w2 > (size_t)st.st_size)
-                       w2 = st.st_size;
-       }
-#endif
        wsize = w2 - wsize;
        while (wsize > 0) {
                if (wsize > MAX_WRITE)