From 0eee938c5fca906994e0f9b9edc7883ea1546eea Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Mon, 22 May 2017 19:59:16 +0300 Subject: [PATCH] mdbx: add MDBX_EIO. --- mdbx_osal.h | 3 ++- src/osal.c | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/mdbx_osal.h b/mdbx_osal.h index da0e2ca4..438b1a95 100644 --- a/mdbx_osal.h +++ b/mdbx_osal.h @@ -101,6 +101,7 @@ typedef DWORD mdbx_tid_t; #define MDBX_ENOMEM ERROR_OUTOFMEMORY #define MDBX_EROFS ERROR_FILE_READ_ONLY #define MDBX_ENOSYS ERROR_NOT_SUPPORTED +#define MDBX_EIO ERROR_WRITE_FAULT #else @@ -118,7 +119,7 @@ typedef pthread_t mdbx_tid_t; #define MDBX_ENOMEM ENOMEM #define MDBX_EROFS EROFS #define MDBX_ENOSYS ENOSYS - +#define MDBX_EIO EIO #endif /*--------------------------------------------------------------------------*/ diff --git a/src/osal.c b/src/osal.c index 459b9f49..0e887dd4 100644 --- a/src/osal.c +++ b/src/osal.c @@ -139,7 +139,7 @@ int mdbx_asprintf(char **strp, const char *fmt, ...) { int mdbx_memalign_alloc(size_t alignment, size_t bytes, void **result) { #if _MSC_VER *result = _aligned_malloc(bytes, alignment); - return *result ? MDB_SUCCESS : ERROR_OUTOFMEMORY; + return *result ? MDB_SUCCESS : MDBX_ENOMEM /* ERROR_OUTOFMEMORY */; #elif __GLIBC_PREREQ(2, 16) || __STDC_VERSION__ >= 201112L *result = memalign(alignment, bytes); return *result ? MDB_SUCCESS : errno; @@ -343,7 +343,7 @@ int mdbx_pread(mdbx_filehandle_t fd, void *buf, size_t bytes, off_t offset) { ssize_t read = pread(fd, buf, bytes, offset); if (read < 0) { int rc = errno; - return (rc == MDB_SUCCESS) ? /* paranoia */ EIO : rc; + return (rc == MDB_SUCCESS) ? /* paranoia */ MDBX_EIO : rc; } #endif return (bytes == (size_t)read) ? MDB_SUCCESS : MDBX_ENODATA; @@ -362,7 +362,7 @@ int mdbx_pwrite(mdbx_filehandle_t fd, const void *buf, size_t bytes, DWORD written; if (likely(WriteFile(fd, buf, (DWORD)bytes, &written, &ov))) - return (bytes == written) ? MDB_SUCCESS : ERROR_WRITE_FAULT; + return (bytes == written) ? MDB_SUCCESS : MDBX_EIO /* ERROR_WRITE_FAULT */; return mdbx_get_errno_checked(); #else int rc; @@ -373,7 +373,7 @@ int mdbx_pwrite(mdbx_filehandle_t fd, const void *buf, size_t bytes, return MDB_SUCCESS; rc = errno; } while (rc == EINTR); - return (written < 0) ? rc : EIO /* Use which error code (ENOSPC)? */; + return (written < 0) ? rc : MDBX_EIO /* Use which error code (ENOSPC)? */; #endif } @@ -388,7 +388,8 @@ int mdbx_pwritev(mdbx_filehandle_t fd, struct iovec *iov, int iovcnt, written += iov[i].iov_len; offset += iov[i].iov_len; } - return (expected_written == written) ? MDB_SUCCESS : ERROR_WRITE_FAULT; + return (expected_written == written) ? MDB_SUCCESS + : MDBX_EIO /* ERROR_WRITE_FAULT */; #else int rc; ssize_t written; @@ -398,7 +399,7 @@ int mdbx_pwritev(mdbx_filehandle_t fd, struct iovec *iov, int iovcnt, return MDB_SUCCESS; rc = errno; } while (rc == EINTR); - return (written < 0) ? rc : EIO /* Use which error code? */; + return (written < 0) ? rc : MDBX_EIO /* Use which error code? */; #endif }