/* util.c -- utility functions for gzip support
- Copyright (C) 1997-1999, 2001-2002, 2006, 2009-2014 Free Software
+ Copyright (C) 1997-1999, 2001-2002, 2006, 2009-2018 Free Software
Foundation, Inc.
Copyright (C) 1992-1993 Jean-loup Gailly
#include <config.h>
#include <ctype.h>
#include <errno.h>
-
-#include "tailor.h"
-
#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
+#include "tailor.h"
#include "gzip.h"
+#include <dirname.h>
#include <xalloc.h>
#ifndef CHAR_BIT
gzip_base_name (fname)
char *fname;
{
- char *p;
-
- if ((p = strrchr(fname, PATH_SEP)) != NULL) fname = p+1;
-#ifdef PATH_SEP2
- if ((p = strrchr(fname, PATH_SEP2)) != NULL) fname = p+1;
-#endif
-#ifdef PATH_SEP3
- if ((p = strrchr(fname, PATH_SEP3)) != NULL) fname = p+1;
-#endif
-#ifdef SUFFIX_SEP
- if ((p = strrchr(fname, SUFFIX_SEP)) != NULL) *p = '\0';
-#endif
+ fname = last_component (fname);
if (casemap('A') == 'a') strlwr(fname);
return fname;
}
} 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(
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;
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.
*/
*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--) {
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;
}