X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=util.c;h=c06bcc42ec7dc7233b0d6402f75997d0ccbc840c;hb=a420fbafe812f9584f4e71cf3bd42f222bae74c8;hp=881c6eedcc9888f40e4fcf337c7ecae2d8ea2567;hpb=3d2df61b0ca3aa4efd9258905402dc2a2c73c14c;p=debian%2Fgzip diff --git a/util.c b/util.c index 881c6ee..c06bcc4 100644 --- a/util.c +++ b/util.c @@ -1,6 +1,6 @@ /* util.c -- utility functions for gzip support - Copyright (C) 1997-1999, 2001-2002, 2006, 2009-2015 Free Software + Copyright (C) 1997-1999, 2001-2002, 2006, 2009-2016 Free Software Foundation, Inc. Copyright (C) 1992-1993 Jean-loup Gailly @@ -21,15 +21,13 @@ #include #include #include - -#include "tailor.h" - #include #include #include #include #include +#include "tailor.h" #include "gzip.h" #include @@ -361,11 +359,15 @@ void make_simple_name(name) } while (p != name); } -/* ======================================================================== - * Add an environment variable (if any) before argv, and update argc. - * Return the expanded environment variable to be freed later, or NULL - * if no options were added to argv. - */ +/* Convert the value of the environment variable ENVVAR_NAME + to a newly allocated argument vector, and set *ARGCP and *ARGVP + to the number of arguments and to the vector, respectively. + Make the new vector's zeroth element equal to the old **ARGVP. + Return a pointer to the newly allocated string storage. + + If the vector would be empty, do not allocate storage, + do not set *ARGCP and *ARGVP, and return NULL. */ + #define SEPARATOR " \t" /* separators in env variable */ char *add_envopt( @@ -376,7 +378,6 @@ char *add_envopt( char *p; /* running pointer through env variable */ char **oargv; /* runs through old argv array */ char **nargv; /* runs through new argv array */ - int oargc = *argcp; /* old argc */ int nargc = 0; /* number of arguments in env variable */ char *env_val; @@ -396,7 +397,7 @@ char *add_envopt( free(env_val); return NULL; } - *argcp += nargc; + *argcp = nargc + 1; /* Allocate the new argv array, with an extra element just in case * the original arg list did not end with a NULL. */ @@ -405,9 +406,7 @@ char *add_envopt( *argvp = nargv; /* Copy the program name first */ - if (oargc-- < 0) - gzip_error ("argc<=0"); - *(nargv++) = *(oargv++); + *nargv++ = *oargv; /* Then copy the environment args */ for (p = env_val; nargc > 0; nargc--) { @@ -416,8 +415,6 @@ char *add_envopt( while (*p++) ; /* skip over word */ } - /* Finally copy the old args and add a NULL (usual convention) */ - while (oargc--) *(nargv++) = *(oargv++); *nargv = NULL; return env_val; }