/* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
- * Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+ * Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
* Copyright (C) 1992-1993 Jean-loup Gailly
* The unzip code was written and put in the public domain by Mark Adler.
* Portions of the lzw code are derived from the public domain 'compress'
*/
static char *license_msg[] = {
-"Copyright 2001 Free Software Foundation",
+"Copyright 2002 Free Software Foundation",
"Copyright 1992-1993 Jean-loup Gailly",
"This program comes with ABSOLUTELY NO WARRANTY.",
"You may redistribute copies of this program",
# define DIR_OPT "NO_DIR"
# endif
#endif
+#ifndef NO_DIR
+# define NO_DIR 0
+#endif
#ifdef CLOSEDIR_VOID
# define CLOSEDIR(d) (closedir(d), 0)
# define CLOSEDIR(d) closedir(d)
#endif
+#if !defined(HAVE_LSTAT) && !defined(lstat)
+# define lstat(name, buf) stat(name, buf)
+#endif
+
#ifdef HAVE_UTIME
# ifdef HAVE_UTIME_H
# include <utime.h>
char *env; /* contents of GZIP env variable */
char **args = NULL; /* argv pointer if GZIP env variable defined */
char *z_suffix; /* default suffix (can be set with --suffix) */
-int z_len; /* strlen(z_suffix) */
+size_t z_len; /* strlen(z_suffix) */
off_t bytes_in; /* number of input bytes */
off_t bytes_out; /* number of output bytes */
int main OF((int argc, char **argv));
int (*work) OF((int infile, int outfile)) = zip; /* function to call */
-#ifndef NO_DIR
+#if ! NO_DIR
local void treat_dir OF((char *dir));
#endif
#ifdef HAVE_UTIME
{
printf ("usage: %s [-%scdfhlLnN%stvV19] [-S suffix] [file ...]\n",
progname,
-#if O_BINARY
- "a",
-#else
- "",
-#endif
-#ifdef NO_DIR
- ""
-#else
- "r"
-#endif
- );
+ O_BINARY ? "a" : "", NO_DIR ? "" : "r");
}
/* ======================================================================== */
" -n --no-name do not save or restore the original name and time stamp",
" -N --name save or restore the original name and time stamp",
" -q --quiet suppress all warnings",
-#ifndef NO_DIR
+#if ! NO_DIR
" -r --recursive operate recursively on directories",
#endif
" -S .suf --suffix .suf use suffix .suf on compressed files",
case 'q':
quiet = 1; verbose = 0; break;
case 'r':
-#ifdef NO_DIR
+#if NO_DIR
fprintf(stderr, "%s: -r not supported on this system\n", progname);
usage();
do_exit(ERROR); break;
#endif
if ((z_len == 0 && !decompress) || z_len > MAX_SUFFIX) {
fprintf(stderr, "%s: incorrect suffix '%s'\n",
- progname, optarg);
+ progname, z_suffix);
do_exit(ERROR);
}
if (do_lzw && !decompress) work = lzw;
/* If the input name is that of a directory, recurse or ignore: */
if (S_ISDIR(istat.st_mode)) {
-#ifndef NO_DIR
+#if ! NO_DIR
if (recursive) {
struct stat st;
st = istat;
struct stat *sbuf;
{
errno = 0;
-#ifdef HAVE_LSTAT
if (!to_stdout && !force) {
return lstat(name, sbuf);
}
-#endif
return stat(name, sbuf);
}
tstat = *statb; /* Just in case OS does not fill all fields */
name[s-1] = '\0';
- res = stat(name, &tstat) == 0 && same_file(statb, &tstat);
+ res = lstat(name, &tstat) == 0 && same_file(statb, &tstat);
name[s-1] = c;
Trace((stderr, " too_long(%s) => %d\n", name, res));
return res;
* instead of silently truncating filenames).
*/
errno = 0;
- while (stat(ofname, &ostat) != 0) {
+ while (lstat(ofname, &ostat) != 0) {
if (errno != ENAMETOOLONG) return 0; /* ofname does not exist */
shorten_name(ofname);
}
#else
- if (stat(ofname, &ostat) != 0) return 0;
+ if (lstat(ofname, &ostat) != 0) return 0;
#endif
/* Check for name truncation on existing file. Do this even on systems
* defining ENAMETOOLONG, because on most systems the strict Posix
*/
if (!decompress && name_too_long(ofname, &ostat)) {
shorten_name(ofname);
- if (stat(ofname, &ostat) != 0) return 0;
+ if (lstat(ofname, &ostat) != 0) return 0;
}
/* Check that the input and output files are different (could be
}
}
-#ifndef NO_DIR
+#if ! NO_DIR
/* ========================================================================
* Recurse through the given directory. This code is taken from ncompress.
if (CLOSEDIR(dirp) != 0)
progerror(dir);
}
-#endif /* ? NO_DIR */
+#endif /* ! NO_DIR */
/* ========================================================================
* Free all dynamically allocated variables and exit with the given code.