diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-09-06 10:06:07 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-09-06 10:06:07 -0400 |
commit | edc9256e95e307092d57cf273ac699f33cb0192b (patch) | |
tree | caca10af727a849131c1d23716cd7d6e3a97487e /src/common | |
parent | 20817403173dcd2f8128c9c8b14491117cdc40b6 (diff) | |
parent | c0c78682508c72940c8c7eee99aaea0da16ce34a (diff) | |
download | tor-edc9256e95e307092d57cf273ac699f33cb0192b.tar.gz tor-edc9256e95e307092d57cf273ac699f33cb0192b.zip |
Merge remote branch 'public/win_unicode_fixes'
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compat.c | 36 | ||||
-rw-r--r-- | src/common/util.c | 20 |
2 files changed, 36 insertions, 20 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index e9101a8d7a..20394b4c5d 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -169,13 +169,17 @@ tor_munmap_file(tor_mmap_t *handle) tor_mmap_t * tor_mmap_file(const char *filename) { - WCHAR wfilename[MAX_PATH]= {0}; + TCHAR tfilename[MAX_PATH]= {0}; tor_mmap_t *res = tor_malloc_zero(sizeof(tor_mmap_t)); int empty = 0; res->file_handle = INVALID_HANDLE_VALUE; res->mmap_handle = NULL; - mbstowcs(wfilename,filename,MAX_PATH); - res->file_handle = CreateFileW(wfilename, +#ifdef UNICODE + mbstowcs(tfilename,filename,MAX_PATH); +#else + strlcpy(tfilename,filename,MAX_PATH); +#endif + res->file_handle = CreateFile(tfilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, @@ -1698,11 +1702,7 @@ get_uname(void) #endif { #ifdef MS_WINDOWS -#if defined (WINCE) - OSVERSIONINFO info; -#else - OSVERSIONINFOEXW info; -#endif + OSVERSIONINFOEX info; int i; const char *plat = NULL; const char *extra = NULL; @@ -1724,13 +1724,17 @@ get_uname(void) }; memset(&info, 0, sizeof(info)); info.dwOSVersionInfoSize = sizeof(info); - if (! GetVersionExW((LPOSVERSIONINFOW)&info)) { + if (! GetVersionEx((LPOSVERSIONINFO)&info)) { strlcpy(uname_result, "Bizarre version of Windows where GetVersionEx" " doesn't work.", sizeof(uname_result)); uname_result_is_set = 1; return uname_result; } +#ifdef UNICODE wcstombs(acsd, info.szCSDVersion, MAX_PATH); +#else + strlcpy(acsd, info.szCSDVersion, sizeof(acsd)); +#endif if (info.dwMajorVersion == 4 && info.dwMinorVersion == 0) { if (info.dwPlatformId == VER_PLATFORM_WIN32_NT) plat = "Windows NT 4.0"; @@ -2517,22 +2521,26 @@ network_init(void) char * format_win32_error(DWORD err) { - LPVOID str = NULL; - char abuf[1024] = {0}; + TCHAR *str = NULL; char *result; /* Somebody once decided that this interface was better than strerror(). */ - FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPWSTR) &str, + (LPVOID)&str, 0, NULL); if (str) { +#ifdef UNICODE + char abuf[1024] = {0}; wcstombs(abuf,str,1024); - result = tor_strdup((char*)abuf); + result = tor_strdup(abuf); +#else + result = tor_strdup(str); +#endif LocalFree(str); /* LocalFree != free() */ } else { result = tor_strdup("<unformattable error>"); diff --git a/src/common/util.c b/src/common/util.c index 2781fa35d6..1d770458f7 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2569,26 +2569,34 @@ tor_listdir(const char *dirname) smartlist_t *result; #ifdef MS_WINDOWS char *pattern; - WCHAR wpattern[MAX_PATH] = {0}; + TCHAR tpattern[MAX_PATH] = {0}; char name[MAX_PATH] = {0}; HANDLE handle; - WIN32_FIND_DATAW findData; + WIN32_FIND_DATA findData; size_t pattern_len = strlen(dirname)+16; pattern = tor_malloc(pattern_len); tor_snprintf(pattern, pattern_len, "%s\\*", dirname); - mbstowcs(wpattern,pattern,MAX_PATH); - if (INVALID_HANDLE_VALUE == (handle = FindFirstFileW(wpattern, &findData))) { +#ifdef UNICODE + mbstowcs(tpattern,pattern,MAX_PATH); +#else + strlcpy(tpattern, pattern, MAX_PATH); +#endif + if (INVALID_HANDLE_VALUE == (handle = FindFirstFile(tpattern, &findData))) { tor_free(pattern); return NULL; } - wcstombs(name,findData.cFileName,MAX_PATH); result = smartlist_create(); while (1) { +#ifdef UNICODE + wcstombs(name,findData.cFileName,MAX_PATH); +#else + strlcpy(name,findData.cFileName,sizeof(name)); +#endif if (strcmp(name, ".") && strcmp(name, "..")) { smartlist_add(result, tor_strdup(name)); } - if (!FindNextFileW(handle, &findData)) { + if (!FindNextFile(handle, &findData)) { DWORD err; if ((err = GetLastError()) != ERROR_NO_MORE_FILES) { char *errstr = format_win32_error(err); |