[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [tor-dev] [Patch] src/test.c
On Thu, Apr 7, 2011 at 6:26 PM, Gisle Vanem <gvanem@xxxxxxxxxxxx> wrote:
> Another patch for this:
Looks good, except that tmp is a non-const variable and the string is
going to be const. Does the tweaked version I attached work for you?
--
Nick
From 70e02914682eb1959d8b385f76b5acf7486158cc Mon Sep 17 00:00:00 2001
From: Gisle Vanem <gvanem@xxxxxxxxxxxx>
Date: Thu, 7 Apr 2011 18:34:11 -0400
Subject: [PATCH] Use GetTempDir instead of hardcoded path to c:\windows\tmp for unittests
---
changes/win_tmp_dir | 4 ++++
src/test/test.c | 14 ++++++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
create mode 100644 changes/win_tmp_dir
diff --git a/changes/win_tmp_dir b/changes/win_tmp_dir
new file mode 100644
index 0000000..13f6e7f
--- /dev/null
+++ b/changes/win_tmp_dir
@@ -0,0 +1,4 @@
+ o Unit tests:
+ - Use GetTempDir to find the proper temporary directory location on
+ Windows when generating temporary files for the unit tests. Patch
+ by Gisle Vanem.
diff --git a/src/test/test.c b/src/test/test.c
index f5b6a22..9b24a99 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -84,10 +84,16 @@ setup_directory(void)
if (is_setup) return;
#ifdef MS_WINDOWS
- // XXXX
- tor_snprintf(temp_dir, sizeof(temp_dir),
- "c:\\windows\\temp\\tor_test_%d", (int)getpid());
- r = mkdir(temp_dir);
+ {
+ char buf[MAX_PATH];
+ const char *tmp = buf;
+ /* If this fails, we're probably screwed anyway */
+ if (!GetTempPath(sizeof(buf),buf))
+ tmp = "c:\\windows\\temp";
+ tor_snprintf(temp_dir, sizeof(temp_dir),
+ "%s\\tor_test_%d", tmp, (int)getpid());
+ r = mkdir(temp_dir);
+ }
#else
tor_snprintf(temp_dir, sizeof(temp_dir), "/tmp/tor_test_%d", (int) getpid());
r = mkdir(temp_dir, 0700);
--
1.7.4.2
_______________________________________________
tor-dev mailing list
tor-dev@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev