static SECURITY_DESCRIPTOR mdb_null_sd;
static SECURITY_ATTRIBUTES mdb_all_sa;
static int mdb_sec_inited;
+
+static int utf8_to_utf16(const char *src, int srcsize, wchar_t **dst, int *dstsize);
#endif
/** Return the library version info. */
off_t size, rsize;
#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_ATTRIBUTE_NORMAL, NULL);
+ free(wlpath);
#else
env->me_lfd = open(lpath, O_RDWR|O_CREAT|MDB_CLOEXEC, mode);
#endif
{
int oflags, rc, len, excl = -1;
char *lpath, *dpath;
+#ifdef _WIN32
+ wchar_t *wpath;
+#endif
if (env->me_fd!=INVALID_HANDLE_VALUE || (flags & ~(CHANGEABLE|CHANGELESS)))
return EINVAL;
len = OPEN_ALWAYS;
}
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);
+ free(wpath);
#else
if (F_ISSET(flags, MDB_RDONLY))
oflags = O_RDONLY;
*/
#ifdef _WIN32
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,
mode | FILE_FLAG_WRITE_THROUGH, NULL);
+ free(wpath);
#else
oflags &= ~O_CREAT;
env->me_mfd = open(dpath, oflags | MDB_DSYNC, mode);
int rc, len;
char *lpath;
HANDLE newfd = INVALID_HANDLE_VALUE;
+#ifdef _WIN32
+ wchar_t *wpath;
+#endif
if (env->me_flags & MDB_NOSUBDIR) {
lpath = (char *)path;
* already in the OS cache.
*/
#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);
+ free(wpath);
#else
newfd = open(lpath, O_WRONLY|O_CREAT|O_EXCL, 0666);
#endif
}
#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) */