mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-18 11:05:48 +08:00
ITS#7992 assume Windows paths are UTF-8
This commit is contained in:
parent
28b57ba8b9
commit
f13b971960
@ -1372,6 +1372,8 @@ static MDB_cmp_func mdb_cmp_memn, mdb_cmp_memnr, mdb_cmp_int, mdb_cmp_cint, mdb_
|
|||||||
static SECURITY_DESCRIPTOR mdb_null_sd;
|
static SECURITY_DESCRIPTOR mdb_null_sd;
|
||||||
static SECURITY_ATTRIBUTES mdb_all_sa;
|
static SECURITY_ATTRIBUTES mdb_all_sa;
|
||||||
static int mdb_sec_inited;
|
static int mdb_sec_inited;
|
||||||
|
|
||||||
|
static int utf8_to_utf16(const char *src, int srcsize, wchar_t **dst, int *dstsize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Return the library version info. */
|
/** Return the library version info. */
|
||||||
@ -4440,9 +4442,12 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
|
|||||||
off_t size, rsize;
|
off_t size, rsize;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
env->me_lfd = CreateFileA(lpath, GENERIC_READ|GENERIC_WRITE,
|
wchar_t *wlpath;
|
||||||
|
utf8_to_utf16(lpath, -1, &wlpath, NULL);
|
||||||
|
env->me_lfd = CreateFileW(wlpath, GENERIC_READ|GENERIC_WRITE,
|
||||||
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
|
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
|
||||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
free(wlpath);
|
||||||
#else
|
#else
|
||||||
env->me_lfd = open(lpath, O_RDWR|O_CREAT|MDB_CLOEXEC, mode);
|
env->me_lfd = open(lpath, O_RDWR|O_CREAT|MDB_CLOEXEC, mode);
|
||||||
#endif
|
#endif
|
||||||
@ -4660,6 +4665,9 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode
|
|||||||
{
|
{
|
||||||
int oflags, rc, len, excl = -1;
|
int oflags, rc, len, excl = -1;
|
||||||
char *lpath, *dpath;
|
char *lpath, *dpath;
|
||||||
|
#ifdef _WIN32
|
||||||
|
wchar_t *wpath;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (env->me_fd!=INVALID_HANDLE_VALUE || (flags & ~(CHANGEABLE|CHANGELESS)))
|
if (env->me_fd!=INVALID_HANDLE_VALUE || (flags & ~(CHANGEABLE|CHANGELESS)))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -4723,8 +4731,10 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode
|
|||||||
len = OPEN_ALWAYS;
|
len = OPEN_ALWAYS;
|
||||||
}
|
}
|
||||||
mode = FILE_ATTRIBUTE_NORMAL;
|
mode = FILE_ATTRIBUTE_NORMAL;
|
||||||
env->me_fd = CreateFileA(dpath, oflags, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
utf8_to_utf16(dpath, -1, &wpath, NULL);
|
||||||
|
env->me_fd = CreateFileW(wpath, oflags, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
||||||
NULL, len, mode, NULL);
|
NULL, len, mode, NULL);
|
||||||
|
free(wpath);
|
||||||
#else
|
#else
|
||||||
if (F_ISSET(flags, MDB_RDONLY))
|
if (F_ISSET(flags, MDB_RDONLY))
|
||||||
oflags = O_RDONLY;
|
oflags = O_RDONLY;
|
||||||
@ -4753,9 +4763,11 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode
|
|||||||
*/
|
*/
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
len = OPEN_EXISTING;
|
len = OPEN_EXISTING;
|
||||||
env->me_mfd = CreateFileA(dpath, oflags,
|
utf8_to_utf16(dpath, -1, &wpath, NULL);
|
||||||
|
env->me_mfd = CreateFileW(wpath, oflags,
|
||||||
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, len,
|
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, len,
|
||||||
mode | FILE_FLAG_WRITE_THROUGH, NULL);
|
mode | FILE_FLAG_WRITE_THROUGH, NULL);
|
||||||
|
free(wpath);
|
||||||
#else
|
#else
|
||||||
oflags &= ~O_CREAT;
|
oflags &= ~O_CREAT;
|
||||||
env->me_mfd = open(dpath, oflags | MDB_DSYNC, mode);
|
env->me_mfd = open(dpath, oflags | MDB_DSYNC, mode);
|
||||||
@ -9145,6 +9157,9 @@ mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags)
|
|||||||
int rc, len;
|
int rc, len;
|
||||||
char *lpath;
|
char *lpath;
|
||||||
HANDLE newfd = INVALID_HANDLE_VALUE;
|
HANDLE newfd = INVALID_HANDLE_VALUE;
|
||||||
|
#ifdef _WIN32
|
||||||
|
wchar_t *wpath;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (env->me_flags & MDB_NOSUBDIR) {
|
if (env->me_flags & MDB_NOSUBDIR) {
|
||||||
lpath = (char *)path;
|
lpath = (char *)path;
|
||||||
@ -9162,8 +9177,10 @@ mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags)
|
|||||||
* already in the OS cache.
|
* already in the OS cache.
|
||||||
*/
|
*/
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
newfd = CreateFileA(lpath, GENERIC_WRITE, 0, NULL, CREATE_NEW,
|
utf8_to_utf16(lpath, -1, &wpath, NULL);
|
||||||
|
newfd = CreateFileW(wpath, GENERIC_WRITE, 0, NULL, CREATE_NEW,
|
||||||
FILE_FLAG_NO_BUFFERING|FILE_FLAG_WRITE_THROUGH, NULL);
|
FILE_FLAG_NO_BUFFERING|FILE_FLAG_WRITE_THROUGH, NULL);
|
||||||
|
free(wpath);
|
||||||
#else
|
#else
|
||||||
newfd = open(lpath, O_WRONLY|O_CREAT|O_EXCL, 0666);
|
newfd = open(lpath, O_WRONLY|O_CREAT|O_EXCL, 0666);
|
||||||
#endif
|
#endif
|
||||||
@ -9868,3 +9885,22 @@ mdb_mutex_failed(MDB_env *env, mdb_mutexref_t mutex, int rc)
|
|||||||
}
|
}
|
||||||
#endif /* MDB_ROBUST_SUPPORTED */
|
#endif /* MDB_ROBUST_SUPPORTED */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
static int utf8_to_utf16(const char *src, int srcsize, wchar_t **dst, int *dstsize)
|
||||||
|
{
|
||||||
|
int need;
|
||||||
|
wchar_t *result;
|
||||||
|
need = MultiByteToWideChar(CP_UTF8, 0, src, srcsize, NULL, 0);
|
||||||
|
if (need == 0xFFFD)
|
||||||
|
return EILSEQ;
|
||||||
|
if (need == 0)
|
||||||
|
return EINVAL;
|
||||||
|
result = malloc(sizeof(wchar_t) * need);
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, src, srcsize, result, need);
|
||||||
|
if (dstsize)
|
||||||
|
*dstsize = need;
|
||||||
|
*dst = result;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* defined(_WIN32) */
|
||||||
|
Loading…
Reference in New Issue
Block a user