mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 01:14:13 +08:00
mdbx: rework mdbx_pread().
This commit is contained in:
parent
aa59522dbe
commit
5ed0ccfcbb
@ -3737,7 +3737,7 @@ static int __cold mdbx_setup_dxb(MDB_env *env, MDB_meta *meta, int lck_rc) {
|
||||
int err = mdbx_read_header(env, meta);
|
||||
if (unlikely(err != MDB_SUCCESS)) {
|
||||
if (lck_rc != /* lck exclusive */ MDBX_RESULT_TRUE || err != MDBX_ENODATA ||
|
||||
(env->me_flags & MDB_RDONLY))
|
||||
(env->me_flags & MDB_RDONLY) != 0)
|
||||
return err;
|
||||
|
||||
mdbx_debug("create new database");
|
||||
|
13
src/osal.c
13
src/osal.c
@ -337,19 +337,16 @@ int mdbx_pread(mdbx_filehandle_t fd, void *buf, size_t bytes, off_t offset) {
|
||||
DWORD read = 0;
|
||||
if (unlikely(!ReadFile(fd, buf, (DWORD)bytes, &read, &ov))) {
|
||||
int rc = GetLastError();
|
||||
if (rc == ERROR_HANDLE_EOF)
|
||||
return (read == 0 && offset == 0) ? MDBX_ENODATA : ERROR_READ_FAULT;
|
||||
return (rc == MDB_SUCCESS) ? /* paranoia */ ERROR_READ_FAULT : rc;
|
||||
}
|
||||
return (read == bytes) ? MDB_SUCCESS : ERROR_READ_FAULT;
|
||||
#else
|
||||
ssize_t read = pread(fd, buf, bytes, offset);
|
||||
if (likely(bytes == (size_t)read))
|
||||
return MDB_SUCCESS;
|
||||
if (read < 0)
|
||||
return errno;
|
||||
return (read == 0 && offset == 0) ? MDBX_ENODATA : EIO;
|
||||
if (read < 0) {
|
||||
int rc = errno;
|
||||
return (rc == MDB_SUCCESS) ? /* paranoia */ EIO : rc;
|
||||
}
|
||||
#endif
|
||||
return (bytes == (size_t)read) ? MDB_SUCCESS : MDBX_ENODATA;
|
||||
}
|
||||
|
||||
int mdbx_pwrite(mdbx_filehandle_t fd, const void *buf, size_t bytes,
|
||||
|
Loading…
x
Reference in New Issue
Block a user