]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add set_environment_variable_in_smartlist
authorRobert Ransom <rransom.8774@gmail.com>
Mon, 13 Feb 2012 05:17:11 +0000 (21:17 -0800)
committerNick Mathewson <nickm@torproject.org>
Fri, 17 Feb 2012 16:42:20 +0000 (11:42 -0500)
src/common/util.c
src/common/util.h

index 02a638e4ca5ea85a35a8972e9a55b00bb9f1197a..c8af6029ec3f43789af1f62462df28a6ce452acf 100644 (file)
@@ -3853,6 +3853,30 @@ get_current_process_environment_variables(void)
   return sl;
 }
 
+/** For each string s in <b>env_vars</b> such that
+ * environment_variable_names_equal(s, <b>new_var</b>), remove it; if
+ * <b>free_p</b> is non-zero, call <b>free_old</b>(s).  If
+ * <b>new_var</b> contains '=', insert it into <b>env_vars</b>. */
+void
+set_environment_variable_in_smartlist(struct smartlist_t *env_vars,
+                                      const char *new_var,
+                                      void (*free_old)(void*),
+                                      int free_p)
+{
+  SMARTLIST_FOREACH_BEGIN(env_vars, const char *, s) {
+    if (environment_variable_names_equal(s, new_var)) {
+      SMARTLIST_DEL_CURRENT(env_vars, s);
+      if (free_p) {
+        free_old((void *)s);
+      }
+    }
+  } SMARTLIST_FOREACH_END(s);
+
+  if (strchr(new_var, '=') != NULL) {
+    smartlist_add(env_vars, (void *)new_var);
+  }
+}
+
 #ifdef _WIN32
 /** Read from a handle <b>h</b> into <b>buf</b>, up to <b>count</b> bytes.  If
  * <b>hProcess</b> is NULL, the function will return immediately if there is
index f4854460695a5b9c3b2e565da28ad43858320efa..9d1baf0a25e0cc2bc6f159c9fd8e178f9a25451e 100644 (file)
@@ -396,6 +396,11 @@ void process_environment_free(process_environment_t *env);
 
 struct smartlist_t *get_current_process_environment_variables(void);
 
+void set_environment_variable_in_smartlist(struct smartlist_t *env_vars,
+                                           const char *new_var,
+                                           void (*free_old)(void*),
+                                           int free_p);
+
 /* Values of process_handle_t.status. PROCESS_STATUS_NOTRUNNING must be
  * 0 because tor_check_port_forwarding depends on this being the initial
  * statue of the static instance of process_handle_t */