[or-cvs] [tor/master] Switch over to tor_strtok_r instead of strtok_r.

Nick Mathewson nickm at seul.org
Fri Aug 14 21:14:03 UTC 2009


Author: Mike Perry <mikeperry-git at fscked.org>
Date: Sun, 9 Aug 2009 18:42:29 -0700
Subject: Switch over to tor_strtok_r instead of strtok_r.
Commit: 9e1fe29bebf57fc38975c552eefaa9cb97dd5c68

---
 src/common/compat.h |    4 ++--
 src/or/dirserv.c    |   20 ++------------------
 src/or/eventdns.c   |   12 ++----------
 3 files changed, 6 insertions(+), 30 deletions(-)

diff --git a/src/common/compat.h b/src/common/compat.h
index 3d42948..edd09d8 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -269,9 +269,9 @@ extern const char TOR_TOLOWER_TABLE[];
 
 char *tor_strtok_r_impl(char *str, const char *sep, char **lasts);
 #ifdef HAVE_STRTOK_R
-#define tor_strok_r(str, sep, lasts) strtok_r(str, sep, lasts)
+#define tor_strtok_r(str, sep, lasts) strtok_r(str, sep, lasts)
 #else
-#define tor_strok_r(str, sep, lasts) tor_strtok_r_impl(str, sep, lasts)
+#define tor_strtok_r(str, sep, lasts) tor_strtok_r_impl(str, sep, lasts)
 #endif
 
 #ifdef MS_WINDOWS
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 32ddcd0..3b7b2ff 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -2224,22 +2224,6 @@ router_clear_status_flags(routerinfo_t *router)
     router->is_bad_exit = router->is_bad_directory = 0;
 }
 
-#ifndef HAVE_STRTOK_R
-/*
- * XXX-MP: If a system lacks strtok_r and we use a non-reentrant strtok,
- * we may introduce odd bugs if we call a codepath that also uses strtok
- * and resets its internal state. Do we want to abandon use of strtok
- * entirely for this reason? Roger mentioned smartlist_split and
- * eat_whitespace() as alternatives.
- */
-static char *
-strtok_r(char *s, const char *delim, char **state)
-{
-  (void)state;
-  return strtok(s, delim);
-}
-#endif
-
 /**
  * Helper function to parse out a line in the measured bandwidth file
  * into a measured_bw_line_t output structure. Returns -1 on failure
@@ -2253,7 +2237,7 @@ measured_bw_line_parse(measured_bw_line_t *out, const char *orig_line)
   int got_bw = 0;
   int got_node_id = 0;
   char *strtok_state; /* lame sauce d'jour */
-  cp = strtok_r(cp, " \t", &strtok_state);
+  cp = tor_strtok_r(cp, " \t", &strtok_state);
 
   if (!cp) {
     log_warn(LD_DIRSERV, "Invalid line in bandwidth file: %s",
@@ -2308,7 +2292,7 @@ measured_bw_line_parse(measured_bw_line_t *out, const char *orig_line)
       strncpy(out->node_hex, cp, sizeof(out->node_hex));
       got_node_id=1;
     }
-  } while ((cp = strtok_r(NULL, " \t", &strtok_state)));
+  } while ((cp = tor_strtok_r(NULL, " \t", &strtok_state)));
 
   if (got_bw && got_node_id) {
     tor_free(line);
diff --git a/src/or/eventdns.c b/src/or/eventdns.c
index 9578b24..b413b6a 100644
--- a/src/or/eventdns.c
+++ b/src/or/eventdns.c
@@ -2889,14 +2889,6 @@ evdns_resolv_set_defaults(int flags) {
 	if (flags & DNS_OPTION_NAMESERVERS) evdns_nameserver_ip_add("127.0.0.1");
 }
 
-#ifndef HAVE_STRTOK_R
-static char *
-strtok_r(char *s, const char *delim, char **state) {
-	(void)state;
-	return strtok(s, delim);
-}
-#endif
-
 /* helper version of atoi which returns -1 on error */
 static int
 strtoint(const char *const str) {
@@ -2973,9 +2965,9 @@ static void
 resolv_conf_parse_line(char *const start, int flags) {
 	char *strtok_state;
 	static const char *const delims = " \t";
-#define NEXT_TOKEN strtok_r(NULL, delims, &strtok_state)
+#define NEXT_TOKEN tor_strtok_r(NULL, delims, &strtok_state)
 
-	char *const first_token = strtok_r(start, delims, &strtok_state);
+	char *const first_token = tor_strtok_r(start, delims, &strtok_state);
 	if (!first_token) return;
 
 	if (!strcmp(first_token, "nameserver") && (flags & DNS_OPTION_NAMESERVERS)) {
-- 
1.5.6.5



More information about the tor-commits mailing list