diff mbox

[2/4] linux-user: Use existing envlist_parse_set/envlist_parse_unset interface.

Message ID 1369835434-27727-3-git-send-email-thomas@codesourcery.com
State New
Headers show

Commit Message

Thomas Schwinge May 29, 2013, 1:50 p.m. UTC
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
---
 linux-user/main.c |   18 ++++--------------
 util/envlist.c    |    4 ++--
 2 files changed, 6 insertions(+), 16 deletions(-)

Comments

Peter Maydell June 27, 2013, 5:49 p.m. UTC | #1
On 29 May 2013 14:50, Thomas Schwinge <thomas@codesourcery.com> wrote:
> Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
> ---
>  linux-user/main.c |   18 ++++--------------
>  util/envlist.c    |    4 ++--
>  2 files changed, 6 insertions(+), 16 deletions(-)
>
> diff --git linux-user/main.c linux-user/main.c
> index b97b8cf..a0ea161 100644
> --- linux-user/main.c
> +++ linux-user/main.c
> @@ -3204,26 +3204,16 @@ static void handle_arg_log_filename(const char *arg)
>
>  static void handle_arg_set_env(const char *arg)
>  {
> -    char *r, *p, *token;
> -    r = p = strdup(arg);
> -    while ((token = strsep(&p, ",")) != NULL) {
> -        if (envlist_setenv(envlist, token) != 0) {
> -            usage();
> -        }
> +    if (envlist_parse_set(envlist, arg) != 0) {
> +        usage();
>      }
> -    free(r);
>  }
>
>  static void handle_arg_unset_env(const char *arg)
>  {
> -    char *r, *p, *token;
> -    r = p = strdup(arg);
> -    while ((token = strsep(&p, ",")) != NULL) {
> -        if (envlist_unsetenv(envlist, token) != 0) {
> -            usage();
> -        }
> +    if (envlist_parse_unset(envlist, arg) != 0) {
> +        usage();
>      }
> -    free(r);
>  }

This looks OK...

>
>  static void handle_arg_argv0(const char *arg)
> diff --git util/envlist.c util/envlist.c
> index cbbf7e5..8027bbf 100644
> --- util/envlist.c
> +++ util/envlist.c
> @@ -55,10 +55,10 @@ envlist_free(envlist_t *envlist)
>
>  /*
>   * Parses comma separated list of set/modify environment
> - * variable entries and updates given enlist accordingly.
> + * variable entries and updates given envlist accordingly.
>   *
>   * For example:
> - *     envlist_parse(el, "HOME=foo,SHELL=/bin/sh");
> + *     envlist_parse_set(el, "HOME=foo,SHELL=/bin/sh");
>   *
>   * inserts/sets environment variables HOME and SHELL.
>   *

...but this bit needs to be a separate patch.

-- PMM
diff mbox

Patch

diff --git linux-user/main.c linux-user/main.c
index b97b8cf..a0ea161 100644
--- linux-user/main.c
+++ linux-user/main.c
@@ -3204,26 +3204,16 @@  static void handle_arg_log_filename(const char *arg)
 
 static void handle_arg_set_env(const char *arg)
 {
-    char *r, *p, *token;
-    r = p = strdup(arg);
-    while ((token = strsep(&p, ",")) != NULL) {
-        if (envlist_setenv(envlist, token) != 0) {
-            usage();
-        }
+    if (envlist_parse_set(envlist, arg) != 0) {
+        usage();
     }
-    free(r);
 }
 
 static void handle_arg_unset_env(const char *arg)
 {
-    char *r, *p, *token;
-    r = p = strdup(arg);
-    while ((token = strsep(&p, ",")) != NULL) {
-        if (envlist_unsetenv(envlist, token) != 0) {
-            usage();
-        }
+    if (envlist_parse_unset(envlist, arg) != 0) {
+        usage();
     }
-    free(r);
 }
 
 static void handle_arg_argv0(const char *arg)
diff --git util/envlist.c util/envlist.c
index cbbf7e5..8027bbf 100644
--- util/envlist.c
+++ util/envlist.c
@@ -55,10 +55,10 @@  envlist_free(envlist_t *envlist)
 
 /*
  * Parses comma separated list of set/modify environment
- * variable entries and updates given enlist accordingly.
+ * variable entries and updates given envlist accordingly.
  *
  * For example:
- *     envlist_parse(el, "HOME=foo,SHELL=/bin/sh");
+ *     envlist_parse_set(el, "HOME=foo,SHELL=/bin/sh");
  *
  * inserts/sets environment variables HOME and SHELL.
  *