#include <9pm/windows.h> #include <9pm/u.h> #include <9pm/libc.h> #pragma comment( lib, "user32.lib" ) int win_useunicode; int win_hasunicode(void) { OSVERSIONINFOA osinfo; int r; osinfo.dwOSVersionInfoSize = sizeof(osinfo); if(!GetVersionExA(&osinfo)) pm_panic("GetVersionEx failed"); switch(osinfo.dwPlatformId) { default: pm_panic("unknown PlatformId"); case VER_PLATFORM_WIN32s: pm_panic("Win32s not supported"); case VER_PLATFORM_WIN32_WINDOWS: r = 0; break; case VER_PLATFORM_WIN32_NT: r = 1; break; } return r; } char* win_wstr2utfn(char *s, int ns, LPCWSTR xr) { int n; char *e, *os; Rune *r; r = (Rune*)xr; os = s; e = s+ns-1; while(s < e){ n = runelen(*r); if(s+n > e) break; s += runetochar(s, r); r++; } *s = '\0'; return os; } char* win_wstr2utf(LPCWSTR xr) { char *s; int len; Rune *r; if(xr == nil) return nil; r = (Rune*)xr; len = runenlen(r, runestrlen(r))+1; s = malloc(len); return win_wstr2utfn(s, len, r); } int win_utf2wstrn(LPWSTR r, DWORD n, char *s) { int len; Rune *e, *or; len = utflen(s); if(len >= n) return len; or = r; e = r+n-1; while(rcFileName-(uchar*)fdw); win_utf2wstrn(fdw->cFileName, sizeof(fdw->cFileName), fda->cFileName); win_utf2wstrn(fdw->cAlternateFileName, sizeof(fdw->cAlternateFileName), fda->cAlternateFileName); }