diff options
author | valerino <valerino@te4i.com> | 2010-05-20 22:53:39 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-05-24 11:46:45 -0400 |
commit | 8d31141ccbdbeee9589d04ea99819af7aa35193b (patch) | |
tree | 42b596b609a885d04a6a985b07b95fbd4d4ce015 /src/common/util.c | |
parent | ddf250119df44927c424512f286a3255aea1d16b (diff) | |
download | tor-8d31141ccbdbeee9589d04ea99819af7aa35193b.tar.gz tor-8d31141ccbdbeee9589d04ea99819af7aa35193b.zip |
Port Tor to work on Windows CE
Most of the changes here are switches to use APIs available on Windows
CE. The most pervasive change is that Windows CE only provides the
wide-character ("FooW") variants of most of the windows function, and
doesn't support the older ASCII verions at all.
This patch will require use of the wcecompat library to get working
versions of the posix-style fd-based file IO functions.
[commit message by nickm]
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/common/util.c b/src/common/util.c index 1c0db392d0..fe48e93284 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1707,7 +1707,7 @@ check_private_dir(const char *dirname, cpd_check_t check) return -1; } else if (check == CPD_CREATE) { log_info(LD_GENERAL, "Creating directory %s", dirname); -#ifdef MS_WINDOWS +#if defined (MS_WINDOWS) && !defined (WINCE) r = mkdir(dirname); #else r = mkdir(dirname, 0700); @@ -1843,7 +1843,8 @@ start_writing_to_file(const char *fname, int open_flags, int mode, if (open_flags & O_BINARY) new_file->binary = 1; - if ((new_file->fd = open(open_name, open_flags, mode)) < 0) { + new_file->fd = open(open_name, open_flags, mode); + if (new_file->fd < 0) { log_warn(LD_FS, "Couldn't open \"%s\" (%s) for writing: %s", open_name, fname, strerror(errno)); goto err; @@ -2526,22 +2527,26 @@ tor_listdir(const char *dirname) smartlist_t *result; #ifdef MS_WINDOWS char *pattern; + WCHAR wpattern[MAX_PATH] = {0}; + char name[MAX_PATH] = {0}; HANDLE handle; - WIN32_FIND_DATA findData; + WIN32_FIND_DATAW findData; size_t pattern_len = strlen(dirname)+16; pattern = tor_malloc(pattern_len); tor_snprintf(pattern, pattern_len, "%s\\*", dirname); - if (INVALID_HANDLE_VALUE == (handle = FindFirstFile(pattern, &findData))) { + mbstowcs(wpattern,pattern,MAX_PATH); + if (INVALID_HANDLE_VALUE == (handle = FindFirstFileW(wpattern, &findData))) { tor_free(pattern); return NULL; } + wcstombs(name,findData.cFileName,MAX_PATH); result = smartlist_create(); while (1) { - if (strcmp(findData.cFileName, ".") && - strcmp(findData.cFileName, "..")) { - smartlist_add(result, tor_strdup(findData.cFileName)); + if (strcmp(name, ".") && + strcmp(name, "..")) { + smartlist_add(result, tor_strdup(name)); } - if (!FindNextFile(handle, &findData)) { + if (!FindNextFileW(handle, &findData)) { DWORD err; if ((err = GetLastError()) != ERROR_NO_MORE_FILES) { char *errstr = format_win32_error(err); |