aboutsummaryrefslogtreecommitdiff
path: root/src/or/main.c
diff options
context:
space:
mode:
authorvalerino <valerino@te4i.com>2010-05-20 22:53:39 -0400
committerNick Mathewson <nickm@torproject.org>2010-05-24 11:46:45 -0400
commit8d31141ccbdbeee9589d04ea99819af7aa35193b (patch)
tree42b596b609a885d04a6a985b07b95fbd4d4ce015 /src/or/main.c
parentddf250119df44927c424512f286a3255aea1d16b (diff)
downloadtor-8d31141ccbdbeee9589d04ea99819af7aa35193b.tar
tor-8d31141ccbdbeee9589d04ea99819af7aa35193b.tar.gz
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/or/main.c')
-rw-r--r--src/or/main.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/or/main.c b/src/or/main.c
index 0ddb65a74..542383526 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -24,6 +24,10 @@
#include <event.h>
#endif
+#if defined (WINCE)
+#include <projects.h>
+#endif
+
void evdns_shutdown(int);
/********* PROTOTYPES **********/
@@ -2104,6 +2108,31 @@ do_hash_password(void)
printf("16:%s\n",output);
}
+#if defined (WINCE)
+int
+find_flashcard_path(PWCHAR path, size_t size)
+{
+ WIN32_FIND_DATA d = {0};
+ HANDLE h = NULL;
+
+ if (!path)
+ return -1;
+
+ h = FindFirstFlashCard(&d);
+ if (h == INVALID_HANDLE_VALUE)
+ return -1;
+
+ if (wcslen(d.cFileName) == 0) {
+ FindClose(h);
+ return -1;
+ }
+
+ wcsncpy(path,d.cFileName,size);
+ FindClose(h);
+ return 0;
+}
+#endif
+
/** Main entry point for the Tor process. Called from main(). */
/* This function is distinct from main() only so we can link main.c into
* the unittest binary without conflicting with the unittests' main. */
@@ -2111,6 +2140,33 @@ int
tor_main(int argc, char *argv[])
{
int result = 0;
+#if defined (WINCE)
+ WCHAR path [MAX_PATH] = {0};
+ WCHAR fullpath [MAX_PATH] = {0};
+ PWCHAR p = NULL;
+ FILE* redir = NULL;
+ FILE* redirdbg = NULL;
+
+ // this is to facilitate debugging by opening
+ // a file on a folder shared by the wm emulator.
+ // if no flashcard (real or emulated) is present,
+ // log files will be written in the root folder
+ if (find_flashcard_path(path,MAX_PATH) == -1)
+ {
+ redir = _wfreopen( L"\\stdout.log", L"w", stdout );
+ redirdbg = _wfreopen( L"\\stderr.log", L"w", stderr );
+ } else {
+ swprintf(fullpath,L"\\%s\\tor",path);
+ CreateDirectory(fullpath,NULL);
+
+ swprintf(fullpath,L"\\%s\\tor\\stdout.log",path);
+ redir = _wfreopen( fullpath, L"w", stdout );
+
+ swprintf(fullpath,L"\\%s\\tor\\stderr.log",path);
+ redirdbg = _wfreopen( fullpath, L"w", stderr );
+ }
+#endif
+
update_approx_time(time(NULL));
tor_threads_init();
init_logging();