[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [tor-dev] [Patch] src/test.c



"Nick Mathewson" <nickm@xxxxxxxxxxxxx> wrote:

Sounds fine to me.  Alternatively, I believe we could just call
GetTempPath(): that's what it's there for.

Agreed. I first thought of using GetTempPath() but that involves another buffer and checking the ret-val. It's safes though. From:
http://msdn.microsoft.com/en-us/library/aa364992(v=vs.85).aspx

The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
 1.. The path specified by the TMP environment variable.
 2.. The path specified by the TEMP environment variable.
 3.. The path specified by the USERPROFILE environment variable.
 4.. The Windows directory.

Another patch for this:

--- ../../Git-latest/src/test/test.c    2011-03-30 08:58:28 -0100
+++ test.c      2011-04-07 21:25:51 -0100
@@ -85,9 +85,15 @@

#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], *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);

--------------

--gv
_______________________________________________
tor-dev mailing list
tor-dev@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev