summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-09-06 10:06:07 -0400
committerNick Mathewson <nickm@torproject.org>2010-09-06 10:06:07 -0400
commitedc9256e95e307092d57cf273ac699f33cb0192b (patch)
treecaca10af727a849131c1d23716cd7d6e3a97487e /src/common/util.c
parent20817403173dcd2f8128c9c8b14491117cdc40b6 (diff)
parentc0c78682508c72940c8c7eee99aaea0da16ce34a (diff)
downloadtor-edc9256e95e307092d57cf273ac699f33cb0192b.tar.gz
tor-edc9256e95e307092d57cf273ac699f33cb0192b.zip
Merge remote branch 'public/win_unicode_fixes'
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c20
1 files changed, 14 insertions, 6 deletions
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);