From 629637d95e066dcef22510f1c151f0405e81e499 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sun, 4 Nov 2018 18:57:08 +0300 Subject: [PATCH] mdbx-osal: add mdbx_fseek(). Change-Id: I5744aa3ba51bd1acaeedd866e6b21a1330c3f711 --- src/osal.c | 13 +++++++++++++ src/osal.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/osal.c b/src/osal.c index 4bb70d92..4f9aad27 100644 --- a/src/osal.c +++ b/src/osal.c @@ -753,6 +753,19 @@ int mdbx_ftruncate(mdbx_filehandle_t fd, uint64_t length) { #endif } +int mdbx_fseek(mdbx_filehandle_t fd, uint64_t pos) { +#if defined(_WIN32) || defined(_WIN64) + LARGE_INTEGER li; + li.QuadPart = pos; + return SetFilePointerEx(fd, li, NULL, FILE_BEGIN) ? MDBX_SUCCESS + : GetLastError(); +#else + STATIC_ASSERT_MSG(sizeof(off_t) >= sizeof(size_t), + "libmdbx requires 64-bit file I/O on 64-bit systems"); + return (lseek(fd, pos, SEEK_SET) < 0) ? errno : MDBX_SUCCESS; +#endif +} + /*----------------------------------------------------------------------------*/ int mdbx_thread_create(mdbx_thread_t *thread, diff --git a/src/osal.h b/src/osal.h index 50416d96..9f9d1a44 100644 --- a/src/osal.h +++ b/src/osal.h @@ -504,6 +504,7 @@ int mdbx_thread_join(mdbx_thread_t thread); int mdbx_filesync(mdbx_filehandle_t fd, bool fullsync); int mdbx_filesize_sync(mdbx_filehandle_t fd); int mdbx_ftruncate(mdbx_filehandle_t fd, uint64_t length); +int mdbx_fseek(mdbx_filehandle_t fd, uint64_t pos); int mdbx_filesize(mdbx_filehandle_t fd, uint64_t *length); int mdbx_openfile(const char *pathname, int flags, mode_t mode, mdbx_filehandle_t *fd, bool exclusive);