Skip to content

Instantly share code, notes, and snippets.

@SaitoAtsushi
Created April 6, 2014 10:21
Show Gist options
  • Save SaitoAtsushi/10004111 to your computer and use it in GitHub Desktop.
Save SaitoAtsushi/10004111 to your computer and use it in GitHub Desktop.
diff --git a/src/gauche/win-compat.h b/src/gauche/win-compat.h
index d3823d2..5237aa6 100755
--- a/src/gauche/win-compat.h
+++ b/src/gauche/win-compat.h
@@ -38,7 +38,7 @@ typedef unsigned long u_long;
#define _BSDTYPES_DEFINED
#endif /* _BSDTYPES_DEFINED */
#ifndef _T
-#define _T(x) (x) /* MSVC unicode macro */
+#define _T(x) TEXT(x) /* MSVC unicode macro */
#endif /* _T */
#endif /* __MINGW32__ */
diff --git a/src/port.c b/src/port.c
index a1cca89..c2e7089 100644
--- a/src/port.c
+++ b/src/port.c
@@ -987,7 +987,11 @@ ScmObj Scm_OpenFilePort(const char *path, int flags, int buffering, int perm)
flags |= O_BINARY;
}
#endif /*GAUCHE_WINDOWS*/
+#if defined(GAUCHE_WINDOWS) && defined(UNICODE)
+ int fd = _wopen(Scm_MBS2WCS(path), flags, perm);
+#else
int fd = open(path, flags, perm);
+#endif
if (fd < 0) return SCM_FALSE;
ScmPortBuffer bufrec;
bufrec.mode = buffering;
diff --git a/src/system.c b/src/system.c
index 371dfe2..5d42a6b 100644
--- a/src/system.c
+++ b/src/system.c
@@ -128,7 +128,7 @@ ScmObj Scm_OffsetToInteger(off_t off)
/*===============================================================
* Windows specific - conversion between mbs and wcs.
*/
-#if defined(_MSC_VER) && defined(_UNICODE)
+#if defined(GAUCHE_WINDOWS) && defined(UNICODE)
#include "win-compat.c"
WCHAR *Scm_MBS2WCS(const char *s)
@@ -2571,7 +2571,7 @@ int link(const char *existing, const char *newpath)
LPSECURITY_ATTRIBUTES);
static pCreateHardLink_t pCreateHardLink = NULL;
BOOL r;
-#if defined(_UNICODE)
+#if defined(UNICODE)
#define CREATEHARDLINK "CreateHardLinkW"
#else
#define CREATEHARDLINK "CreateHardLinkA"
diff --git a/src/win-compat.c b/src/win-compat.c
index a513e8b..d0c7922 100755
--- a/src/win-compat.c
+++ b/src/win-compat.c
@@ -14,7 +14,7 @@
static WCHAR *mbs2wcs(const char *s, void (*errfn)(const char *, ...))
{
WCHAR *wb;
- int nc = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, s, -1, NULL, 0);
+ int nc = MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
if (nc == 0) {
errfn("Windows error %d on MultiByteToWideChar", GetLastError());
}
@@ -23,7 +23,7 @@ static WCHAR *mbs2wcs(const char *s, void (*errfn)(const char *, ...))
#else
wb = (WCHAR*)malloc(nc * sizeof(WCHAR));
#endif
- if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, s, -1, wb, nc) == 0) {
+ if (MultiByteToWideChar(CP_UTF8, 0, s, -1, wb, nc) == 0) {
errfn("Windows error %d on MultiByteToWideChar", GetLastError());
}
return wb;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment