diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-08-20 12:30:25 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-08-20 13:40:01 -0400 |
commit | c0c78682508c72940c8c7eee99aaea0da16ce34a (patch) | |
tree | 274e45ffaddd3ea8316e7de1f56cf4e9b76746ec /src/common | |
parent | 34551cda6f699cee5816a5935b56787ccb7b8f67 (diff) | |
download | tor-c0c78682508c72940c8c7eee99aaea0da16ce34a.tar.gz tor-c0c78682508c72940c8c7eee99aaea0da16ce34a.zip |
Make the windows build succeed with or without -DUNICODE enabled.
This should keep WinCE working (unicode always-on) and get Win98
working again (unicode never-on).
There are two places where we explicitly use ASCII-only APIs, still:
in ntmain.c and in the unit tests.
This patch also fixes a bug in windoes tor_listdir that would cause
the first file to be listed an arbitrary number of times that was
also introduced with WinCE support.
Should fix bug 1797.
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 6830ef3aa4..0f50dfedea 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2526,26 +2526,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); |