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/util.c | |
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/util.c')
-rw-r--r-- | src/common/util.c | 20 |
1 files changed, 14 insertions, 6 deletions
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); |