To do this, we've implemented fz_wchar_from_utf8 to mirror
fz_utf8_from_wchar.
*/
char *fz_utf8_from_wchar(fz_context *ctx, const wchar_t *s);
+/*
+ Convert a utf8 string into a new heap allocated wchar one.
+*/
+wchar_t *fz_wchar_from_utf8(fz_context *ctx, const char *path);
+
/**
Locale-independent decimal to binary conversion. On overflow
int
fz_is_directory(fz_context *ctx, const char *path)
{
+#ifdef _WIN32
+ wchar_t *wpath = fz_wchar_from_utf8(ctx, path);
+ struct stat info;
+ int ret;
+
+ ret = _wstat(wpath, &info);
+ fz_free(ctx, wpath);
+ if (ret < 0)
+ return 0;
+
+ return S_ISDIR(info.st_mode);
+#else
struct stat info;
if (stat(path, &info) < 0)
return 0;
return S_ISDIR(info.st_mode);
+#endif
}
static int
return d;
}
+
+wchar_t *
+fz_wchar_from_utf8(fz_context *ctx, const char *path)
+{
+ size_t z = 0;
+ const char *p = path;
+ wchar_t *wpath, *w;
+
+ if (!path)
+ return NULL;
+
+ while (*p)
+ {
+ int c;
+ p += fz_chartorune(&c, p);
+ z++;
+ if (c >= 0x10000)
+ z++;
+ }
+
+ w = wpath = fz_malloc(ctx, 2*(z+1));
+ while (*path)
+ {
+ int c;
+ path += fz_chartorune(&c, path);
+ if (c >= 0x10000)
+ {
+ c -= 0x10000;
+ *w++ = 0xd800 + (c>>10);
+ *w++ = 0xdc00 + (c&1023);
+ }
+ else
+ *w++ = c;
+ }
+ *w = 0;
+
+ return wpath;
+}