mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-30 22:47:16 +08:00
mdbx-windows: use CreateFileW() instead of CreateFileA().
Resolves https://github.com/leo-yuriev/libmdbx/issues/66 Change-Id: I0266a8a77460940332045c19cb561553a5047e7c
This commit is contained in:
parent
fff19d878f
commit
b7ed67543f
27
mdbx.h
27
mdbx.h
@ -1457,13 +1457,13 @@ LIBMDBX_API int mdbx_env_create(MDBX_env **penv);
|
|||||||
* Indifferently this function will fails or not, the mdbx_env_close() must be
|
* Indifferently this function will fails or not, the mdbx_env_close() must be
|
||||||
* called later to discard the MDBX_env handle and release associated resources.
|
* called later to discard the MDBX_env handle and release associated resources.
|
||||||
*
|
*
|
||||||
* [in] env An environment handle returned by mdbx_env_create()
|
* [in] env An environment handle returned by mdbx_env_create()
|
||||||
* [in] path The directory in which the database files reside.
|
* [in] pathname The directory in which the database files reside.
|
||||||
* This directory must already exist and be writable.
|
* This directory must already exist and be writable.
|
||||||
* [in] flags Special options for this environment. This parameter
|
* [in] flags Special options for this environment. This parameter
|
||||||
* must be set to 0 or by bitwise OR'ing together one
|
* must be set to 0 or by bitwise OR'ing together one
|
||||||
* or more of the values described above in the
|
* or more of the values described above in the
|
||||||
* "ENVIRONMENT FLAGS" and "SYNC MODES" sections.
|
* "ENVIRONMENT FLAGS" and "SYNC MODES" sections.
|
||||||
*
|
*
|
||||||
* Flags set by mdbx_env_set_flags() are also used:
|
* Flags set by mdbx_env_set_flags() are also used:
|
||||||
* - MDBX_NOSUBDIR, MDBX_RDONLY, MDBX_EXCLUSIVE, MDBX_WRITEMAP, MDBX_NOTLS,
|
* - MDBX_NOSUBDIR, MDBX_RDONLY, MDBX_EXCLUSIVE, MDBX_WRITEMAP, MDBX_NOTLS,
|
||||||
@ -1514,8 +1514,8 @@ LIBMDBX_API int mdbx_env_create(MDBX_env **penv);
|
|||||||
* after a system crash.
|
* after a system crash.
|
||||||
* - MDBX_TOO_LARGE = Database is too large for this process, i.e.
|
* - MDBX_TOO_LARGE = Database is too large for this process, i.e.
|
||||||
* 32-bit process tries to open >4Gb database. */
|
* 32-bit process tries to open >4Gb database. */
|
||||||
LIBMDBX_API int mdbx_env_open(MDBX_env *env, const char *path, unsigned flags,
|
LIBMDBX_API int mdbx_env_open(MDBX_env *env, const char *pathname,
|
||||||
mode_t mode);
|
unsigned flags, mode_t mode);
|
||||||
|
|
||||||
/* Copy an MDBX environment to the specified path, with options.
|
/* Copy an MDBX environment to the specified path, with options.
|
||||||
*
|
*
|
||||||
@ -1527,7 +1527,7 @@ LIBMDBX_API int mdbx_env_open(MDBX_env *env, const char *path, unsigned flags,
|
|||||||
*
|
*
|
||||||
* [in] env An environment handle returned by mdbx_env_create(). It must
|
* [in] env An environment handle returned by mdbx_env_create(). It must
|
||||||
* have already been opened successfully.
|
* have already been opened successfully.
|
||||||
* [in] path The directory in which the copy will reside. This directory
|
* [in] dest The directory in which the copy will reside. This directory
|
||||||
* must already exist and be writable but must otherwise be empty.
|
* must already exist and be writable but must otherwise be empty.
|
||||||
* [in] flags Special options for this operation. This parameter must be set
|
* [in] flags Special options for this operation. This parameter must be set
|
||||||
* to 0 or by bitwise OR'ing together one or more of the values
|
* to 0 or by bitwise OR'ing together one or more of the values
|
||||||
@ -1540,8 +1540,7 @@ LIBMDBX_API int mdbx_env_open(MDBX_env *env, const char *path, unsigned flags,
|
|||||||
* account skipping free pages.
|
* account skipping free pages.
|
||||||
*
|
*
|
||||||
* Returns A non-zero error value on failure and 0 on success. */
|
* Returns A non-zero error value on failure and 0 on success. */
|
||||||
LIBMDBX_API int mdbx_env_copy(MDBX_env *env, const char *dest_path,
|
LIBMDBX_API int mdbx_env_copy(MDBX_env *env, const char *dest, unsigned flags);
|
||||||
unsigned flags);
|
|
||||||
|
|
||||||
/* Copy an MDBX environment to the specified file descriptor,
|
/* Copy an MDBX environment to the specified file descriptor,
|
||||||
* with options.
|
* with options.
|
||||||
@ -1821,14 +1820,14 @@ LIBMDBX_API int mdbx_env_get_flags(MDBX_env *env, unsigned *flags);
|
|||||||
/* Return the path that was used in mdbx_env_open().
|
/* Return the path that was used in mdbx_env_open().
|
||||||
*
|
*
|
||||||
* [in] env An environment handle returned by mdbx_env_create()
|
* [in] env An environment handle returned by mdbx_env_create()
|
||||||
* [out] path Address of a string pointer to contain the path.
|
* [out] dest Address of a string pointer to contain the path.
|
||||||
* This is the actual string in the environment, not a copy.
|
* This is the actual string in the environment, not a copy.
|
||||||
* It should not be altered in any way.
|
* It should not be altered in any way.
|
||||||
*
|
*
|
||||||
* Returns A non-zero error value on failure and 0 on success, some
|
* Returns A non-zero error value on failure and 0 on success, some
|
||||||
* possible errors are:
|
* possible errors are:
|
||||||
* - MDBX_EINVAL = an invalid parameter was specified. */
|
* - MDBX_EINVAL = an invalid parameter was specified. */
|
||||||
LIBMDBX_API int mdbx_env_get_path(MDBX_env *env, const char **path);
|
LIBMDBX_API int mdbx_env_get_path(MDBX_env *env, const char **dest);
|
||||||
|
|
||||||
/* Return the file descriptor for the given environment.
|
/* Return the file descriptor for the given environment.
|
||||||
*
|
*
|
||||||
|
@ -505,6 +505,12 @@ MDBX_INTERNAL_FUNC int mdbx_openfile(const char *pathname, int flags,
|
|||||||
*fd = INVALID_HANDLE_VALUE;
|
*fd = INVALID_HANDLE_VALUE;
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
(void)mode;
|
(void)mode;
|
||||||
|
size_t wlen = mbstowcs(nullptr, pathname, INT_MAX);
|
||||||
|
if (wlen < 1 || wlen > /* MAX_PATH */ INT16_MAX)
|
||||||
|
return ERROR_INVALID_NAME;
|
||||||
|
wchar_t *const pathnameW = _alloca((wlen + 1) * sizeof(wchar_t));
|
||||||
|
if (wlen != mbstowcs(pathnameW, pathname, wlen + 1))
|
||||||
|
return ERROR_INVALID_NAME;
|
||||||
|
|
||||||
DWORD DesiredAccess, ShareMode;
|
DWORD DesiredAccess, ShareMode;
|
||||||
DWORD FlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
|
DWORD FlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
|
||||||
@ -544,7 +550,7 @@ MDBX_INTERNAL_FUNC int mdbx_openfile(const char *pathname, int flags,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*fd = CreateFileA(pathname, DesiredAccess, ShareMode, NULL,
|
*fd = CreateFileW(pathnameW, DesiredAccess, ShareMode, NULL,
|
||||||
CreationDisposition, FlagsAndAttributes, NULL);
|
CreationDisposition, FlagsAndAttributes, NULL);
|
||||||
|
|
||||||
if (*fd == INVALID_HANDLE_VALUE)
|
if (*fd == INVALID_HANDLE_VALUE)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user