#ifdef _WIN32
-// MSVC 2008 or later can't produce the binary for Win9x.
-#if !defined(_MSC_VER) || (_MSC_VER < 1500)
+# include <windows.h>
namespace
{
+ // Check if the running system has CreateFileW() function.
+ // Windows9x systems don't have CreateFileW() or can't accept Unicode file names.
- // Determines whether or not the running system is WinNT.
- // In other words, whether the system supports Unicode.
-
- bool isWinNT()
+ bool supportsUnicode()
{
- OSVERSIONINFOA ver = {};
- ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
- if(GetVersionExA(&ver)) {
- return (ver.dwPlatformId == VER_PLATFORM_WIN32_NT);
- }
- else {
- return false;
- }
+ const FARPROC p = GetProcAddress(GetModuleHandleA("kernel32"), "CreateFileW");
+ return (p != NULL);
}
+
+ // Indicates whether the system supports Unicode file names.
- const bool IsWinNT = isWinNT();
+ const bool SystemSupportsUnicode = supportsUnicode();
// Converts a UTF-16 string into a local encoding.
+ // This function should only be used in Windows9x systems which don't support
+ // Unicode file names.
std::string unicodeToAnsi(const std::wstring &wstr)
{
// If Win9x, converts and stores it into m_name to avoid calling Unicode version functions.
FileName::FileName(const wchar_t *name)
- : m_wname(IsWinNT ? name : L"")
- , m_name(IsWinNT ? "" : unicodeToAnsi(name))
-{
-}
-
-#else
-
-FileName::FileName(const wchar_t *name)
- : m_wname(name)
+ : m_wname(SystemSupportsUnicode ? name : L"")
+ , m_name (SystemSupportsUnicode ? "" : unicodeToAnsi(name))
{
}
-#endif
-
FileName::FileName(const char *name)
: m_name(name)
{
FileName::FileName(const FileName &name)
: m_wname(name.m_wname)
- , m_name(name.m_name)
+ , m_name (name.m_name)
{
}
return m_name;
}
-#endif
+#endif // _WIN32
////////////////////////////////////////////////////////////////////////////////
// public members