mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-30 01:54:13 +08:00
mdbx: add mdbx_osal.h with platform-like err codes.
This commit is contained in:
parent
f7507110ef
commit
2e54210e79
2
Makefile
2
Makefile
@ -42,7 +42,7 @@ LIBRARIES := libmdbx.a libmdbx.so
|
||||
TOOLS := mdbx_stat mdbx_copy mdbx_dump mdbx_load mdbx_chk
|
||||
MANPAGES := mdbx_stat.1 mdbx_copy.1 mdbx_dump.1 mdbx_load.1
|
||||
|
||||
MDBX_SRC := mdbx.h $(addprefix src/, mdbx.c osal.c lck-posix.c defs.h bits.h osal.h midl.h)
|
||||
MDBX_SRC := mdbx.h mdbx_osal.h $(addprefix src/, mdbx.c osal.c lck-posix.c defs.h bits.h osal.h midl.h)
|
||||
|
||||
.PHONY: mdbx all install clean check coverage
|
||||
|
||||
|
@ -3,6 +3,7 @@ LICENSE
|
||||
Makefile
|
||||
README.md
|
||||
mdbx.h
|
||||
mdbx_osal.h
|
||||
src/bits.h
|
||||
src/defs.h
|
||||
src/lck-posix.c
|
||||
|
89
mdbx.h
89
mdbx.h
@ -52,95 +52,8 @@
|
||||
|
||||
#ifndef _MDBX_H_
|
||||
#define _MDBX_H_
|
||||
#define MDBX_MODE_ENABLED 1
|
||||
|
||||
#ifndef __has_attribute
|
||||
# define __has_attribute(x) (0)
|
||||
#endif
|
||||
|
||||
#ifndef __dll_export
|
||||
# if defined(_WIN32) || defined(__CYGWIN__)
|
||||
# if defined(__GNUC__) || __has_attribute(dllexport)
|
||||
# define __dll_export __attribute__((dllexport))
|
||||
# elif defined(_MSC_VER)
|
||||
# define __dll_export __declspec(dllexport)
|
||||
# else
|
||||
# define __dll_export
|
||||
# endif
|
||||
# elif defined(__GNUC__) || __has_attribute(visibility)
|
||||
# define __dll_export __attribute__((visibility("default")))
|
||||
# else
|
||||
# define __dll_export
|
||||
# endif
|
||||
#endif /* __dll_export */
|
||||
|
||||
#ifndef __dll_import
|
||||
# if defined(_WIN32) || defined(__CYGWIN__)
|
||||
# if defined(__GNUC__) || __has_attribute(dllimport)
|
||||
# define __dll_import __attribute__((dllimport))
|
||||
# elif defined(_MSC_VER)
|
||||
# define __dll_import __declspec(dllimport)
|
||||
# else
|
||||
# define __dll_import
|
||||
# endif
|
||||
# else
|
||||
# define __dll_import
|
||||
# endif
|
||||
#endif /* __dll_import */
|
||||
|
||||
#if defined(LIBMDBX_EXPORTS)
|
||||
# define LIBMDBX_API __dll_export
|
||||
#elif defined(LIBMDBX_IMPORTS)
|
||||
# define LIBMDBX_API __dll_import
|
||||
#else
|
||||
# define LIBMDBX_API
|
||||
#endif /* LIBMDBX_API */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4514) /* 'xyz': unreferenced inline function \
|
||||
has been removed */
|
||||
#pragma warning(disable : 4710) /* 'xyz': function not inlined */
|
||||
#pragma warning(disable : 4711) /* function 'xyz' selected for \
|
||||
automatic inline expansion */
|
||||
#pragma warning(disable : 4061) /* enumerator 'abc' in switch of enum \
|
||||
'xyz' is not explicitly handled by a case \
|
||||
label */
|
||||
#pragma warning(disable : 4201) /* nonstandard extension used : \
|
||||
nameless struct / union */
|
||||
#pragma warning(disable : 4127) /* conditional expression is constant \
|
||||
*/
|
||||
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning(disable : 4530) /* C++ exception handler used, but \
|
||||
unwind semantics are not enabled. Specify \
|
||||
/EHsc */
|
||||
#pragma warning(disable : 4577) /* 'noexcept' used with no exception \
|
||||
handling mode specified; termination on \
|
||||
exception is not guaranteed. Specify /EHsc \
|
||||
*/
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
# include <windows.h>
|
||||
# include <winnt.h>
|
||||
typedef unsigned mode_t;
|
||||
typedef HANDLE mdbx_filehandle_t;
|
||||
typedef DWORD mdbx_pid_t;
|
||||
typedef DWORD mdbx_tid_t;
|
||||
#else
|
||||
# include <pthread.h> /* for pthread_t */
|
||||
# include <sys/uio.h> /* for truct iovec */
|
||||
# include <sys/types.h> /* for pid_t */
|
||||
# define HAVE_STRUCT_IOVEC 1
|
||||
typedef int mdbx_filehandle_t;
|
||||
typedef pid_t mdbx_pid_t;
|
||||
typedef pthread_t mdbx_tid_t;
|
||||
#endif
|
||||
#include "mdbx_osal.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
|
120
mdbx_osal.h
Normal file
120
mdbx_osal.h
Normal file
@ -0,0 +1,120 @@
|
||||
/* https://en.wikipedia.org/wiki/Operating_system_abstraction_layer */
|
||||
|
||||
/*
|
||||
* Copyright 2015-2017 Leonid Yuriev <leo@yuriev.ru>
|
||||
* and other libmdbx authors: please see AUTHORS file.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted only as authorized by the OpenLDAP
|
||||
* Public License.
|
||||
*
|
||||
* A copy of this license is available in the file LICENSE in the
|
||||
* top-level directory of the distribution or, alternatively, at
|
||||
* <http://www.OpenLDAP.org/license.html>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __has_attribute
|
||||
#define __has_attribute(x) (0)
|
||||
#endif
|
||||
|
||||
#ifndef __dll_export
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
#if defined(__GNUC__) || __has_attribute(dllexport)
|
||||
#define __dll_export __attribute__((dllexport))
|
||||
#elif defined(_MSC_VER)
|
||||
#define __dll_export __declspec(dllexport)
|
||||
#else
|
||||
#define __dll_export
|
||||
#endif
|
||||
#elif defined(__GNUC__) || __has_attribute(visibility)
|
||||
#define __dll_export __attribute__((visibility("default")))
|
||||
#else
|
||||
#define __dll_export
|
||||
#endif
|
||||
#endif /* __dll_export */
|
||||
|
||||
#ifndef __dll_import
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
#if defined(__GNUC__) || __has_attribute(dllimport)
|
||||
#define __dll_import __attribute__((dllimport))
|
||||
#elif defined(_MSC_VER)
|
||||
#define __dll_import __declspec(dllimport)
|
||||
#else
|
||||
#define __dll_import
|
||||
#endif
|
||||
#else
|
||||
#define __dll_import
|
||||
#endif
|
||||
#endif /* __dll_import */
|
||||
|
||||
#if defined(LIBMDBX_EXPORTS)
|
||||
#define LIBMDBX_API __dll_export
|
||||
#elif defined(LIBMDBX_IMPORTS)
|
||||
#define LIBMDBX_API __dll_import
|
||||
#else
|
||||
#define LIBMDBX_API
|
||||
#endif /* LIBMDBX_API */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4514) /* 'xyz': unreferenced inline function \
|
||||
has been removed */
|
||||
#pragma warning(disable : 4710) /* 'xyz': function not inlined */
|
||||
#pragma warning(disable : 4711) /* function 'xyz' selected for \
|
||||
automatic inline expansion */
|
||||
#pragma warning(disable : 4061) /* enumerator 'abc' in switch of enum \
|
||||
'xyz' is not explicitly handled by a case \
|
||||
label */
|
||||
#pragma warning(disable : 4201) /* nonstandard extension used : \
|
||||
nameless struct / union */
|
||||
#pragma warning(disable : 4127) /* conditional expression is constant \
|
||||
*/
|
||||
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning(disable : 4530) /* C++ exception handler used, but \
|
||||
unwind semantics are not enabled. Specify \
|
||||
/EHsc */
|
||||
#pragma warning(disable : 4577) /* 'noexcept' used with no exception \
|
||||
handling mode specified; termination on \
|
||||
exception is not guaranteed. Specify /EHsc \
|
||||
*/
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
#include <winnt.h>
|
||||
typedef unsigned mode_t;
|
||||
typedef HANDLE mdbx_filehandle_t;
|
||||
typedef DWORD mdbx_pid_t;
|
||||
typedef DWORD mdbx_tid_t;
|
||||
|
||||
#define MDBX_ENODATA ERROR_HANDLE_EOF
|
||||
#define MDBX_EINVAL ERROR_INVALID_PARAMETER
|
||||
#define MDBX_EACCESS ERROR_ACCESS_DENIED
|
||||
#define MDBX_ENOMEM ERROR_OUTOFMEMORY
|
||||
|
||||
#else
|
||||
#include <errno.h> /* for error codes */
|
||||
#include <pthread.h> /* for pthread_t */
|
||||
#include <sys/types.h> /* for pid_t */
|
||||
#include <sys/uio.h> /* for truct iovec */
|
||||
#define HAVE_STRUCT_IOVEC 1
|
||||
typedef int mdbx_filehandle_t;
|
||||
typedef pid_t mdbx_pid_t;
|
||||
typedef pthread_t mdbx_tid_t;
|
||||
|
||||
#define MDBX_ENODATA ENODATA
|
||||
#define MDBX_EINVAL EINVAL
|
||||
#define MDBX_EACCESS EACCES
|
||||
#define MDBX_ENOMEM ENOMEM
|
||||
|
||||
#endif
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
280
src/mdbx.c
280
src/mdbx.c
File diff suppressed because it is too large
Load Diff
@ -337,7 +337,7 @@ int mdbx_pread(mdbx_filehandle_t fd, void *buf, size_t bytes, off_t offset) {
|
||||
if (unlikely(!ReadFile(fd, buf, (DWORD)bytes, &read, &ov))) {
|
||||
int rc = GetLastError();
|
||||
if (rc == ERROR_HANDLE_EOF && read == 0 && offset == 0)
|
||||
return ENOENT;
|
||||
return MDBX_ENODATA;
|
||||
return rc;
|
||||
}
|
||||
return (read == bytes) ? MDB_SUCCESS : ERROR_READ_FAULT;
|
||||
@ -347,7 +347,7 @@ int mdbx_pread(mdbx_filehandle_t fd, void *buf, size_t bytes, off_t offset) {
|
||||
return MDB_SUCCESS;
|
||||
if (read < 0)
|
||||
return errno;
|
||||
return (read == 0 && offset == 0) ? ENOENT : EIO;
|
||||
return (read == 0 && offset == 0) ? MDBX_ENODATA : EIO;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <malloc.h>
|
||||
|
Loading…
x
Reference in New Issue
Block a user