[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tyndur-devel] [PATCH 1/3] shell: set -d



On Sat, Dec 05 14:36, Kevin Wolf wrote:
> ! libc: setenv() beruecksichtigt den overwrite-Parameter jetzt
> + shell: set -d setzt einen Defaultwert fuer eine Umgebungsvariable.
>   Wenn die Variable bereits gesetzt ist, bleibt sie unveraendert.
> 
> Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
> ---
>  src/modules/c/shell/commmands.c |   21 +++++++++++++++++++--
>  src/modules/lib/envvars.c       |    2 +-
>  2 files changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/src/modules/c/shell/commmands.c b/src/modules/c/shell/commmands.c
> index 897c937..6c33478 100644
> --- a/src/modules/c/shell/commmands.c
> +++ b/src/modules/c/shell/commmands.c
> @@ -287,6 +287,21 @@ void set_list_vars(void);
>  
>  int shell_command_set(int argc, char* argv[], const char* args)
>  {
> +    int overwrite = 1;
> +
> +    while (argc > 1) {
> +        if (!strcmp(argv[1], "-d")) {
> +            overwrite = 0;
> +        } else if (!strcmp(argv[1], "-h")) {
> +            set_display_usage();
> +            return EXIT_SUCCESS;
> +        } else {
> +            break;
> +        }
> +        argc--;
> +        argv++;
> +    }
> +
>      switch (argc) {
>          case 1:
>              set_list_vars();
> @@ -297,7 +312,7 @@ int shell_command_set(int argc, char* argv[], const char* args)
>              break;
>  
>          case 3:
> -            setenv(argv[1], argv[2], 1);
> +            setenv(argv[1], argv[2], overwrite);
>              break;
>  
>          default:
> @@ -320,6 +335,8 @@ void set_list_vars()
>  
>  void set_display_usage()
>  {
> -    puts("\nAufruf: set [<Variable> [<Wert>]]\n");
> +    puts("\nAufruf: set [-d] [<Variable> [<Wert>]]");
> +    puts("  -d: Defaultwert setzen. Wenn die Variable schon gesetzt ist, wird "
> +        "ihr Wert\n      nicht ge??ndert.\n");
>  }
>  
> diff --git a/src/modules/lib/envvars.c b/src/modules/lib/envvars.c
> index 12ba4f6..323cd86 100644
> --- a/src/modules/lib/envvars.c
> +++ b/src/modules/lib/envvars.c
> @@ -261,7 +261,7 @@ int setenv(const char* name, const char* value, int overwrite)
>  
>          //In die Liste einfuegen
>          envvar_list = list_push(envvar_list, envvar);
> -    } else {
> +    } else if (overwrite) {
>          char* new_value = malloc(strlen(value) + 1);
>          memcpy(new_value, value, strlen(value) + 1);
>          
> -- 
> 1.6.0.2
> 

Acked-by: Antoine Kaufmann <toni@xxxxxxxxxx>

-- 
Antoine Kaufmann
<toni@xxxxxxxxxxxxxxxx>

Attachment: pgpEWca1Iuoye.pgp
Description: PGP signature