[or-cvs] [tor/master 7/7] Make expand_filename into a tor_strdup() alias on windows.

nickm at torproject.org nickm at torproject.org
Mon Feb 22 17:47:26 UTC 2010


Author: Nick Mathewson <nickm at torproject.org>
Date: Mon, 22 Feb 2010 12:42:31 -0500
Subject: Make expand_filename into a tor_strdup() alias on windows.
Commit: d35b8dc5827762cd9cbee90f57ef370f477539fb

On Windows, we don't have a notion of ~ meaning "our homedir", so we
were deliberately using an #ifdef to avoid calling expand_filename()
in multiple places.  This is silly: The right place to turn a function
into a no-op on a single platform is in the function itself, not in
every single call-site.
---
 src/common/util.c        |    4 ++++
 src/or/config.c          |    6 ------
 src/tools/tor-checkkey.c |    4 ----
 3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/common/util.c b/src/common/util.c
index a15af7e..f7e5dd0 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2312,6 +2312,9 @@ char *
 expand_filename(const char *filename)
 {
   tor_assert(filename);
+#ifdef MS_WINDOWS
+  return tor_strdup(filename);
+#else
   if (*filename == '~') {
     size_t len;
     char *home, *result;
@@ -2361,6 +2364,7 @@ expand_filename(const char *filename)
   } else {
     return tor_strdup(filename);
   }
+#endif
 }
 
 #define MAX_SCANF_WIDTH 9999
diff --git a/src/or/config.c b/src/or/config.c
index 0453904..5ad1d3f 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -3839,13 +3839,7 @@ find_torrc_filename(int argc, char **argv,
         log(LOG_WARN, LD_CONFIG, "Duplicate -f options on command line.");
         tor_free(fname);
       }
-#ifdef MS_WINDOWS
-      /* XXX one day we might want to extend expand_filename to work
-       * under Windows as well. */
-      fname = tor_strdup(argv[i+1]);
-#else
       fname = expand_filename(argv[i+1]);
-#endif
       *using_default_torrc = 0;
       ++i;
     } else if (!strcmp(argv[i],"--ignore-missing-torrc")) {
diff --git a/src/tools/tor-checkkey.c b/src/tools/tor-checkkey.c
index 30c223a..e15cc46 100644
--- a/src/tools/tor-checkkey.c
+++ b/src/tools/tor-checkkey.c
@@ -47,11 +47,7 @@ int main(int c, char **v)
     fname_idx = 1;
   }
 
-#ifdef MS_WINDOWS
-  fname = tor_strdup(v[fname_idx]);
-#else
   fname = expand_filename(v[fname_idx]);
-#endif
   str = read_file_to_str(fname, 0, NULL);
   tor_free(fname);
   if (!str) {
-- 
1.6.5



More information about the tor-commits mailing list