mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 00:54:14 +08:00
mdbx-windows: ликвидация макроса OSAL_MB2WIDE()
.
This commit is contained in:
parent
351a30f186
commit
ebbe98afa5
32
src/core.c
32
src/core.c
@ -14487,9 +14487,11 @@ __cold int mdbx_env_open_for_recovery(MDBX_env *env, const char *pathname,
|
||||
unsigned target_meta, bool writeable) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
wchar_t *pathnameW = nullptr;
|
||||
OSAL_MB2WIDE(pathname, pathnameW);
|
||||
int rc = mdbx_env_open_for_recoveryW(env, pathnameW, target_meta, writeable);
|
||||
osal_free(pathnameW);
|
||||
int rc = osal_mb2w(pathname, &pathnameW);
|
||||
if (likely(rc == MDBX_SUCCESS)) {
|
||||
rc = mdbx_env_open_for_recoveryW(env, pathnameW, target_meta, writeable);
|
||||
osal_free(pathnameW);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -14678,9 +14680,11 @@ __cold static int handle_env_pathname(MDBX_handle_env_pathname *ctx,
|
||||
__cold int mdbx_env_delete(const char *pathname, MDBX_env_delete_mode_t mode) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
wchar_t *pathnameW = nullptr;
|
||||
OSAL_MB2WIDE(pathname, pathnameW);
|
||||
int rc = mdbx_env_deleteW(pathnameW, mode);
|
||||
osal_free(pathnameW);
|
||||
int rc = osal_mb2w(pathname, &pathnameW);
|
||||
if (likely(rc == MDBX_SUCCESS)) {
|
||||
rc = mdbx_env_deleteW(pathnameW, mode);
|
||||
osal_free(pathnameW);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -14771,9 +14775,11 @@ __cold int mdbx_env_open(MDBX_env *env, const char *pathname,
|
||||
MDBX_env_flags_t flags, mdbx_mode_t mode) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
wchar_t *pathnameW = nullptr;
|
||||
OSAL_MB2WIDE(pathname, pathnameW);
|
||||
int rc = mdbx_env_openW(env, pathnameW, flags, mode);
|
||||
osal_free(pathnameW);
|
||||
int rc = osal_mb2w(pathname, &pathnameW);
|
||||
if (likely(rc == MDBX_SUCCESS)) {
|
||||
rc = mdbx_env_openW(env, pathnameW, flags, mode);
|
||||
osal_free(pathnameW);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -21779,9 +21785,11 @@ __cold int mdbx_env_copy(MDBX_env *env, const char *dest_path,
|
||||
MDBX_copy_flags_t flags) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
wchar_t *dest_pathW = nullptr;
|
||||
OSAL_MB2WIDE(dest_path, dest_pathW);
|
||||
int rc = mdbx_env_copyW(env, dest_pathW, flags);
|
||||
osal_free(dest_pathW);
|
||||
int rc = osal_mb2w(dest_path, &dest_pathW);
|
||||
if (likely(rc == MDBX_SUCCESS)) {
|
||||
rc = mdbx_env_copyW(env, dest_pathW, flags);
|
||||
osal_free(dest_pathW);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
37
src/osal.c
37
src/osal.c
@ -546,19 +546,32 @@ MDBX_INTERNAL_FUNC int osal_fastmutex_release(osal_fastmutex_t *fastmutex) {
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#ifndef WC_ERR_INVALID_CHARS
|
||||
static const DWORD WC_ERR_INVALID_CHARS =
|
||||
(6 /* Windows Vista */ <= /* MajorVersion */ LOBYTE(LOWORD(GetVersion())))
|
||||
? 0x00000080
|
||||
: 0;
|
||||
#endif /* WC_ERR_INVALID_CHARS */
|
||||
MDBX_INTERNAL_FUNC int osal_mb2w(const char *const src, wchar_t **const pdst) {
|
||||
const size_t dst_wlen = MultiByteToWideChar(
|
||||
CP_THREAD_ACP, MB_ERR_INVALID_CHARS, src, -1, nullptr, 0);
|
||||
wchar_t *dst = *pdst;
|
||||
int rc = ERROR_INVALID_NAME;
|
||||
if (unlikely(dst_wlen < 2 || dst_wlen > /* MAX_PATH */ INT16_MAX))
|
||||
goto bailout;
|
||||
|
||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL_FUNC size_t osal_mb2w(wchar_t *dst,
|
||||
size_t dst_n,
|
||||
const char *src,
|
||||
size_t src_n) {
|
||||
return MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, src,
|
||||
(int)src_n, dst, (int)dst_n);
|
||||
dst = osal_realloc(dst, dst_wlen * sizeof(wchar_t));
|
||||
rc = MDBX_ENOMEM;
|
||||
if (unlikely(!dst))
|
||||
goto bailout;
|
||||
|
||||
*pdst = dst;
|
||||
if (likely(dst_wlen == (size_t)MultiByteToWideChar(CP_THREAD_ACP,
|
||||
MB_ERR_INVALID_CHARS, src,
|
||||
-1, dst, (int)dst_wlen)))
|
||||
return MDBX_SUCCESS;
|
||||
|
||||
rc = ERROR_INVALID_NAME;
|
||||
bailout:
|
||||
if (*pdst) {
|
||||
osal_free(*pdst);
|
||||
*pdst = nullptr;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif /* Windows */
|
||||
|
21
src/osal.h
21
src/osal.h
@ -757,26 +757,7 @@ MDBX_INTERNAL_FUNC int osal_rpid_check(MDBX_env *env, uint32_t pid);
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
MDBX_INTERNAL_FUNC size_t osal_mb2w(wchar_t *dst, size_t dst_n, const char *src,
|
||||
size_t src_n);
|
||||
|
||||
#define OSAL_MB2WIDE(FROM, TO) \
|
||||
do { \
|
||||
const char *const from_tmp = (FROM); \
|
||||
const size_t from_mblen = strlen(from_tmp); \
|
||||
const size_t to_wlen = osal_mb2w(nullptr, 0, from_tmp, from_mblen); \
|
||||
if (unlikely(to_wlen < 1 || to_wlen > /* MAX_PATH */ INT16_MAX)) \
|
||||
return ERROR_INVALID_NAME; \
|
||||
wchar_t *const to_tmp = osal_malloc((to_wlen + 1) * sizeof(wchar_t)); \
|
||||
if (unlikely(!to_tmp)) \
|
||||
return MDBX_ENOMEM; \
|
||||
if (unlikely(to_wlen + 1 != \
|
||||
osal_mb2w(to_tmp, to_wlen + 1, from_tmp, from_mblen + 1))) { \
|
||||
osal_free(to_tmp); \
|
||||
return ERROR_INVALID_NAME; \
|
||||
} \
|
||||
(TO) = to_tmp; \
|
||||
} while (0)
|
||||
MDBX_INTERNAL_FUNC int osal_mb2w(const char *const src, wchar_t **const pdst);
|
||||
|
||||
typedef void(WINAPI *osal_srwlock_t_function)(osal_srwlock_t *);
|
||||
MDBX_INTERNAL_VAR osal_srwlock_t_function osal_srwlock_Init,
|
||||
|
Loading…
x
Reference in New Issue
Block a user