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

[or-cvs] r9782: We have a PATH_SEPARATOR macro. How about we use it? (in tor/trunk: . src/common src/or)



Author: nickm
Date: 2007-03-09 16:39:30 -0500 (Fri, 09 Mar 2007)
New Revision: 9782

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/common/util.c
   tor/trunk/src/or/config.c
   tor/trunk/src/or/control.c
   tor/trunk/src/or/hibernate.c
   tor/trunk/src/or/main.c
   tor/trunk/src/or/rendservice.c
   tor/trunk/src/or/router.c
   tor/trunk/src/or/routerlist.c
Log:
 r12474@Kushana:  nickm | 2007-03-06 16:10:05 -0500
 We have a PATH_SEPARATOR macro.  How about we use it?



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r12474] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-03-09 21:39:19 UTC (rev 9781)
+++ tor/trunk/ChangeLog	2007-03-09 21:39:30 UTC (rev 9782)
@@ -21,7 +21,12 @@
       since 0.1.2.2-alpha, and all the servers seem to be using the new
       eventdns code.
 
+  o Minor bufixes (portability):
+    - Even though windows is equally happy with / and \ as path separators,
+      try to use \ consistently on windows and / consistently on unix: it
+      makes the log messages nicer.
 
+
 Changes in version 0.1.2.10-rc - 2007-03-07
   o Major bugfixes (Windows):
     - Do not load the NT services library functions (which may not exist)

Modified: tor/trunk/src/common/util.c
===================================================================
--- tor/trunk/src/common/util.c	2007-03-09 21:39:19 UTC (rev 9781)
+++ tor/trunk/src/common/util.c	2007-03-09 21:39:30 UTC (rev 9782)
@@ -1549,14 +1549,14 @@
     }
     tor_assert(home);
     /* Remove trailing slash. */
-    if (strlen(home)>1 && !strcmpend(home,"/")) {
+    if (strlen(home)>1 && !strcmpend(home,PATH_SEPARATOR)) {
       home[strlen(home)-1] = '\0';
     }
     /* Plus one for /, plus one for NUL.
      * Round up to 16 in case we can't do math. */
     len = strlen(home)+strlen(rest)+16;
     result = tor_malloc(len);
-    tor_snprintf(result,len,"%s/%s",home,rest?rest:"");
+    tor_snprintf(result,len,"%s"PATH_SEPARATOR"%s",home,rest?rest:"");
     tor_free(home);
     return result;
   } else {

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2007-03-09 21:39:19 UTC (rev 9781)
+++ tor/trunk/src/or/config.c	2007-03-09 21:39:30 UTC (rev 9782)
@@ -907,7 +907,8 @@
   if (running_tor) {
     len = strlen(options->DataDirectory)+32;
     fn = tor_malloc(len);
-    tor_snprintf(fn, len, "%s/cached-status", options->DataDirectory);
+    tor_snprintf(fn, len, "%s"PATH_SEPARATOR"cached-status",
+                 options->DataDirectory);
     if (check_private_dir(fn, CPD_CREATE) != 0) {
       log_err(LD_CONFIG,
               "Couldn't access/create private data directory \"%s\"", fn);
@@ -3516,11 +3517,10 @@
       * want. */
      log_warn(LD_CONFIG,
               "Default DataDirectory is \"~/.tor\".  This expands to "
-              "\"%s\", which is probably not what you want.  Using \"%s/tor\" "
-              "instead", fn, LOCALSTATEDIR);
+              "\"%s\", which is probably not what you want.  Using "
+              "\"%s"PATH_SEPARATOR"tor\" instead", fn, LOCALSTATEDIR);
      tor_free(fn);
-     fn = tor_strdup(LOCALSTATEDIR"/tor");
-
+     fn = tor_strdup(LOCALSTATEDIR PATH_SEPARATOR "tor");
    }
    tor_free(options->DataDirectory);
    options->DataDirectory = fn;
@@ -3933,7 +3933,7 @@
   or_options_t *options = get_options();
   size_t len = strlen(options->DataDirectory) + 16;
   fname = tor_malloc(len);
-  tor_snprintf(fname, len, "%s/state", options->DataDirectory);
+  tor_snprintf(fname, len, "%s"PATH_SEPARATOR"state", options->DataDirectory);
   return fname;
 }
 

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2007-03-09 21:39:19 UTC (rev 9781)
+++ tor/trunk/src/or/control.c	2007-03-09 21:39:30 UTC (rev 9782)
@@ -3205,7 +3205,7 @@
     return 0;
   }
 
-  tor_snprintf(fname, sizeof(fname), "%s/control_auth_cookie",
+  tor_snprintf(fname, sizeof(fname), "%s"PATH_SEPARATOR"control_auth_cookie",
                get_options()->DataDirectory);
   crypto_rand(authentication_cookie, AUTHENTICATION_COOKIE_LEN);
   authentication_cookie_is_set = 1;

Modified: tor/trunk/src/or/hibernate.c
===================================================================
--- tor/trunk/src/or/hibernate.c	2007-03-09 21:39:19 UTC (rev 9781)
+++ tor/trunk/src/or/hibernate.c	2007-03-09 21:39:30 UTC (rev 9782)
@@ -588,7 +588,7 @@
                U64_PRINTF_ARG(ROUND_UP(n_bytes_written_in_interval)),
                (unsigned long)n_seconds_active_in_interval,
                (unsigned long)expected);
-  tor_snprintf(fname, sizeof(fname), "%s/bw_accounting",
+  tor_snprintf(fname, sizeof(fname), "%s"PATH_SEPARATOR"bw_accounting",
                get_options()->DataDirectory);
   if (!get_options()->AvoidDiskWrites || (last_recorded + 3600 < now)) {
     r = write_str_to_file(fname, buf, 0);

Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c	2007-03-09 21:39:19 UTC (rev 9781)
+++ tor/trunk/src/or/main.c	2007-03-09 21:39:30 UTC (rev 9782)
@@ -1189,7 +1189,7 @@
     router_rebuild_descriptor(1);
     descriptor = router_get_my_descriptor();
     if (descriptor) {
-      tor_snprintf(keydir,sizeof(keydir),"%s/router.desc",
+      tor_snprintf(keydir,sizeof(keydir),"%s"PATH_SEPARATOR"router.desc",
                    options->DataDirectory);
       log_info(LD_OR,"Saving descriptor to \"%s\"...",keydir);
       if (write_str_to_file(keydir, descriptor, 0)) {

Modified: tor/trunk/src/or/rendservice.c
===================================================================
--- tor/trunk/src/or/rendservice.c	2007-03-09 21:39:19 UTC (rev 9781)
+++ tor/trunk/src/or/rendservice.c	2007-03-09 21:39:30 UTC (rev 9782)
@@ -344,7 +344,8 @@
 
     /* Load key */
     if (strlcpy(fname,s->directory,sizeof(fname)) >= sizeof(fname) ||
-        strlcat(fname,"/private_key",sizeof(fname)) >= sizeof(fname)) {
+        strlcat(fname,PATH_SEPARATOR"private_key",sizeof(fname))
+                                                  >= sizeof(fname)) {
       log_warn(LD_CONFIG, "Directory name too long to store key file: \"%s\".",
                s->directory);
       return -1;
@@ -363,7 +364,8 @@
       return -1;
     }
     if (strlcpy(fname,s->directory,sizeof(fname)) >= sizeof(fname) ||
-        strlcat(fname,"/hostname",sizeof(fname)) >= sizeof(fname)) {
+        strlcat(fname,PATH_SEPARATOR"hostname",sizeof(fname))
+                                                  >= sizeof(fname)) {
       log_warn(LD_CONFIG, "Directory name too long to store hostname file:"
                " \"%s\".", s->directory);
       return -1;

Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c	2007-03-09 21:39:19 UTC (rev 9781)
+++ tor/trunk/src/or/router.c	2007-03-09 21:39:30 UTC (rev 9782)
@@ -133,9 +133,11 @@
   or_state_t *state = get_or_state();
   time_t now;
   tor_snprintf(fname,sizeof(fname),
-           "%s/keys/secret_onion_key",get_options()->DataDirectory);
+               "%s"PATH_SEPARATOR"keys"PATH_SEPARATOR"secret_onion_key",
+               get_options()->DataDirectory);
   tor_snprintf(fname_prev,sizeof(fname_prev),
-           "%s/keys/secret_onion_key.old",get_options()->DataDirectory);
+               "%s"PATH_SEPARATOR"keys"PATH_SEPARATOR"secret_onion_key.old",
+               get_options()->DataDirectory);
   if (!(prkey = crypto_new_pk_env())) {
     log_err(LD_GENERAL,"Error constructing rotated onion key");
     goto error;
@@ -267,19 +269,21 @@
     return -1;
   }
   /* Check the key directory. */
-  tor_snprintf(keydir,sizeof(keydir),"%s/keys", datadir);
+  tor_snprintf(keydir,sizeof(keydir),"%s"PATH_SEPARATOR"keys", datadir);
   if (check_private_dir(keydir, CPD_CREATE)) {
     return -1;
   }
 
   /* 1. Read identity key. Make it if none is found. */
-  tor_snprintf(keydir,sizeof(keydir),"%s/keys/secret_id_key",datadir);
+  tor_snprintf(keydir,sizeof(keydir),
+               "%s"PATH_SEPARATOR"keys"PATH_SEPARATOR"secret_id_key",datadir);
   log_info(LD_GENERAL,"Reading/making identity key \"%s\"...",keydir);
   prkey = init_key_from_file(keydir);
   if (!prkey) return -1;
   set_identity_key(prkey);
   /* 2. Read onion key.  Make it if none is found. */
-  tor_snprintf(keydir,sizeof(keydir),"%s/keys/secret_onion_key",datadir);
+  tor_snprintf(keydir,sizeof(keydir),
+             "%s"PATH_SEPARATOR"keys"PATH_SEPARATOR"secret_onion_key",datadir);
   log_info(LD_GENERAL,"Reading/making onion key \"%s\"...",keydir);
   prkey = init_key_from_file(keydir);
   if (!prkey) return -1;
@@ -295,7 +299,8 @@
     or_state_mark_dirty(state, options->AvoidDiskWrites ? time(NULL)+3600 : 0);
   }
 
-  tor_snprintf(keydir,sizeof(keydir),"%s/keys/secret_onion_key.old",datadir);
+  tor_snprintf(keydir,sizeof(keydir),
+         "%s"PATH_SEPARATOR"keys"PATH_SEPARATOR"secret_onion_key.old",datadir);
   if (file_status(keydir) == FN_FILE) {
     prkey = init_key_from_file(keydir);
     if (prkey)
@@ -330,7 +335,7 @@
   }
 
   /* 5. Dump fingerprint to 'fingerprint' */
-  tor_snprintf(keydir,sizeof(keydir),"%s/fingerprint", datadir);
+  tor_snprintf(keydir,sizeof(keydir),"%s"PATH_SEPARATOR"fingerprint", datadir);
   log_info(LD_GENERAL,"Dumping fingerprint to \"%s\"...",keydir);
   if (crypto_pk_get_fingerprint(get_identity_key(), fingerprint, 1)<0) {
     log_err(LD_GENERAL,"Error computing fingerprint");

Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c	2007-03-09 21:39:19 UTC (rev 9781)
+++ tor/trunk/src/or/routerlist.c	2007-03-09 21:39:30 UTC (rev 9782)
@@ -125,7 +125,7 @@
   if (!networkstatus_list)
     networkstatus_list = smartlist_create();
 
-  tor_snprintf(filename,sizeof(filename),"%s/cached-status",
+  tor_snprintf(filename,sizeof(filename),"%s"PATH_SEPARATOR"cached-status",
                get_options()->DataDirectory);
   entries = tor_listdir(filename);
   SMARTLIST_FOREACH(entries, const char *, fn, {
@@ -136,7 +136,8 @@
                  "Skipping cached-status file with unexpected name \"%s\"",fn);
         continue;
       }
-      tor_snprintf(filename,sizeof(filename),"%s/cached-status/%s",
+      tor_snprintf(filename,sizeof(filename),
+                   "%s"PATH_SEPARATOR"cached-status"PATH_SEPARATOR"%s",
                    get_options()->DataDirectory, fn);
       s = read_file_to_str(filename, 0, &st);
       if (s) {
@@ -196,7 +197,7 @@
   const char *body = signed_descriptor_get_body(desc);
   size_t len = desc->signed_descriptor_len;
 
-  tor_snprintf(fname, fname_len, "%s/cached-routers.new",
+  tor_snprintf(fname, fname_len, "%s"PATH_SEPARATOR"cached-routers.new",
                options->DataDirectory);
 
   tor_assert(len == strlen(body));
@@ -264,9 +265,10 @@
   fname_len = strlen(options->DataDirectory)+32;
   fname = tor_malloc(fname_len);
   fname_tmp = tor_malloc(fname_len);
-  tor_snprintf(fname, fname_len, "%s/cached-routers", options->DataDirectory);
-  tor_snprintf(fname_tmp, fname_len, "%s/cached-routers.tmp",
+  tor_snprintf(fname, fname_len, "%s"PATH_SEPARATOR"cached-routers",
                options->DataDirectory);
+  tor_snprintf(fname_tmp, fname_len, "%s"PATH_SEPARATOR"cached-routers.tmp",
+               options->DataDirectory);
 
   chunk_list = smartlist_create();
 
@@ -331,7 +333,7 @@
     });
   }
 
-  tor_snprintf(fname, fname_len, "%s/cached-routers.new",
+  tor_snprintf(fname, fname_len, "%s"PATH_SEPARATOR"cached-routers.new",
                options->DataDirectory);
 
   write_str_to_file(fname, "", 1);
@@ -364,7 +366,8 @@
 
   router_journal_len = router_store_len = 0;
 
-  tor_snprintf(fname, fname_len, "%s/cached-routers", options->DataDirectory);
+  tor_snprintf(fname, fname_len, "%s"PATH_SEPARATOR"cached-routers",
+               options->DataDirectory);
 
   if (routerlist->mmap_descriptors) /* get rid of it first */
     tor_munmap_file(routerlist->mmap_descriptors);
@@ -376,7 +379,7 @@
                                     SAVED_IN_CACHE, NULL);
   }
 
-  tor_snprintf(fname, fname_len, "%s/cached-routers.new",
+  tor_snprintf(fname, fname_len, "%s"PATH_SEPARATOR"cached-routers.new",
                options->DataDirectory);
   if (file_status(fname) == FN_FILE)
     contents = read_file_to_str(fname, RFTS_BIN|RFTS_IGNORE_MISSING, NULL);
@@ -2352,7 +2355,8 @@
   char fp[HEX_DIGEST_LEN+1];
   char *fn = tor_malloc(len+1);
   base16_encode(fp, HEX_DIGEST_LEN+1, identity_digest, DIGEST_LEN);
-  tor_snprintf(fn, len, "%s/cached-status/%s",datadir,fp);
+  tor_snprintf(fn, len, "%s"PATH_SEPARATOR"cached-status"PATH_SEPARATOR"%s",
+               datadir,fp);
   return fn;
 }