I don't think it's a good idea to use hard-coded paths. Even in a test source-file. Easy patch:
--- Git-latest\src\test\test.c Wed Mar 30 11:58:28 2011 +++ src\test\test.c Thu Mar 31 14:06:14 2011 @@ -86,7 +86,7 @@ #ifdef MS_WINDOWS // XXXX tor_snprintf(temp_dir, sizeof(temp_dir), - "c:\windows\temp\tor_test_%d", (int)getpid()); + "%s\tor_test_%d", getenv("TEMP"), (int)getpid()); r = mkdir(temp_dir); #else tor_snprintf(temp_dir, sizeof(temp_dir), "/tmp/tor_test_%d", (int) getpid());
----------
--gv
On Thu, Apr 7, 2011 at 3:48 PM, Gisle Vanem gvanem@broadpark.no wrote:
I don't think it's a good idea to use hard-coded paths. Even in a test source-file. Easy patch:
--- Git-latest\src\test\test.c Wed Mar 30 11:58:28 2011 +++ src\test\test.c Thu Mar 31 14:06:14 2011 @@ -86,7 +86,7 @@ #ifdef MS_WINDOWS // XXXX tor_snprintf(temp_dir, sizeof(temp_dir),
- "c:\windows\temp\tor_test_%d", (int)getpid());
- "%s\tor_test_%d", getenv("TEMP"), (int)getpid());
r = mkdir(temp_dir); #else tor_snprintf(temp_dir, sizeof(temp_dir), "/tmp/tor_test_%d", (int) getpid());
What guarantees that TEMP will always be defined?
On Thu, Apr 07, 2011 at 05:10:05PM -0400, Nick Mathewson wrote:
On Thu, Apr 7, 2011 at 3:48 PM, Gisle Vanem gvanem@broadpark.no wrote:
- "c:\windows\temp\tor_test_%d", (int)getpid());
- "%s\tor_test_%d", getenv("TEMP"), (int)getpid());
What guarantees that TEMP will always be defined?
A Windows (or DOS) system with %TEMP% undefined can reasonably be expected to not work properly. On the other hand, a Windows system which doesn't have a C: drive should work correctly. We could be a bit defensive and if %TEMP% isn't defined, fall back on C:\WINDOWS\TEMP?
Steven.
On Thu, Apr 7, 2011 at 5:17 PM, Steven J. Murdoch tor+Steven.Murdoch@cl.cam.ac.uk wrote:
On Thu, Apr 07, 2011 at 05:10:05PM -0400, Nick Mathewson wrote:
On Thu, Apr 7, 2011 at 3:48 PM, Gisle Vanem gvanem@broadpark.no wrote:
- "c:\windows\temp\tor_test_%d", (int)getpid());
- "%s\tor_test_%d", getenv("TEMP"), (int)getpid());
What guarantees that TEMP will always be defined?
A Windows (or DOS) system with %TEMP% undefined can reasonably be expected to not work properly. On the other hand, a Windows system which doesn't have a C: drive should work correctly. We could be a bit defensive and if %TEMP% isn't defined, fall back on C:\WINDOWS\TEMP?
Sounds fine to me. Alternatively, I believe we could just call GetTempPath(): that's what it's there for.
"Nick Mathewson" nickm@freehaven.net 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
On Thu, Apr 7, 2011 at 6:26 PM, Gisle Vanem gvanem@broadpark.no 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?