setfile(outfile, &sb);
setfile(outfile, entry->fts_statp);
main(argc, argv)	int argc;	char *argv[];{	struct stat sb, osb;	const struct compressor *method;	char *p, *s, *infile, outfile[MAXPATHLEN], suffix[16];	char *nargv[512];	/* some estimate based on ARG_MAX */	int exists, isreg, oreg, ch, error, i, rc = 0;	bits = cat = decomp = 0;	p = __progname;	if (p[0] == 'g') {		method = M_DEFLATE;		bits = 6;		p++;	} else		method = M_COMPRESS;	decomp = 0;	if (!strcmp(p, "zcat")) {		decomp++;		cat++;	} else {		if (p[0] == 'u' && p[1] == 'n') {			p += 2;			decomp++;		}		if (strcmp(p, "zip") &&		    strcmp(p, "compress"))			errx(1, "unknown program name");	}	strlcpy(suffix, method->suffix, sizeof(suffix));	outfile[0] = '\0';	if ((s = getenv("GZIP")) != NULL) {		char *last;		nargv[0] = *argv++;		for (i = 1, (p = strtok_r(s, " ", &last)); p;		    (p = strtok_r(NULL, " ", &last)), i++)			if (i < sizeof(nargv)/sizeof(nargv[1]) - argc - 1)				nargv[i] = p;			else {				errx(1, "GZIP is too long");			}		argc += i - 1;		while ((nargv[i++] = *argv++))			;		argv = nargv;	}	while ((ch = getopt_long(argc, argv, OPTSTRING, longopts, NULL)) != -1)		switch(ch) {		case '1':		case '2':		case '3':		case '4':		case '5':		case '6':		case '7':		case '8':		case '9':			method = M_DEFLATE;			strlcpy(suffix, method->suffix, sizeof(suffix));			bits = ch - '0';			break;		case 'a':			warnx("option -a is ignored on this system");			break;		case 'b':			bits = strtol(optarg, &p, 10);			/*			 * POSIX 1002.3 says 9 <= bits <= 14 for portable			 * apps, but says the implementation may allow			 * greater.			 */			if (*p)				errx(1, "illegal bit count -- %s", optarg);			break;		case 'c':			cat++;			break;		case 'd':		/* Backward compatible. */			decomp++;			break;		case 'f':			force++;			break;		case 'g':			method = M_DEFLATE;			strlcpy(suffix, method->suffix, sizeof(suffix));			bits = 6;			break;		case 'l':			list++;			break;		case 'n':			nosave++;			break;		case 'N':			nosave = 0;	/* XXX not yet */			break;		case 'O':			method = M_COMPRESS;			strlcpy(suffix, method->suffix, sizeof(suffix));			break;		case 'o':			if (strlcpy(outfile, optarg,			    sizeof(outfile)) >= sizeof(outfile))				errx(1, "-o argument is too long");			break;		case 'q':			verbose = -1;			break;		case 'S':			p = suffix;			if (optarg[0] != '.')				*p++ = '.';			strlcpy(p, optarg, sizeof(suffix) - (p - suffix));			p = optarg;			break;		case 't':			testmode++;			break;		case 'V':			printf("%s\n%s\n%s\n", main_rcsid,			    z_rcsid, gz_rcsid);			return (0);		case 'v':			verbose++;			break;		case 'L':			fputs(copyright, stderr);			fputs(license, stderr);			return (0);		case 'r':			recurse++; /* XXX not yet */			break;		case 'h':		case '?':		default:			usage();		}	argc -= optind;	argv += optind;	do {		if (*argv != NULL) {			infile = *argv;			if (outfile[0] == '\0') {				if (!decomp && !cat) {					int len;					char *p;					if (snprintf(outfile, sizeof(outfile),					    "%s%s", infile, suffix) >= sizeof(outfile))						errx(1, "out file name is too long");					p = strrchr(outfile, '/');					if (p == NULL) p = outfile;					len = strlen(p);					if (len > NAME_MAX) {						errx(1, "filename%s too long",							suffix);					}				} else if (decomp && !cat) {					char *p = strrchr(infile, '.');					if (p != NULL)						for (method = &c_table[0];						     method->name != NULL &&							!strcmp(p, method->suffix);						     method++)							;					if (method->name != NULL)						strlcpy(outfile, infile,						    min(sizeof(outfile),							(p - infile) + 1));				}			}		} else {			infile = "/dev/stdin";			pipin++;		}		if (testmode)			strcpy(outfile, _PATH_DEVNULL);		else if (cat || outfile[0] == '\0') {			strcpy(outfile, "/dev/stdout");			cat++;		}		exists = !stat(outfile, &sb);		if (!force && exists && S_ISREG(sb.st_mode) &&		    !permission(outfile)) {			argv++;			continue;		}		isreg = oreg = !exists || S_ISREG(sb.st_mode);		if (stat(infile, &sb) != 0 && verbose >= 0)			err(1, "input: %s", infile);		if (!S_ISREG(sb.st_mode))			isreg = 0;		if (verbose > 0)			fprintf(stderr, "%s:\t", infile);		error = (decomp? decompress: compress)			(infile, outfile, method, bits, &sb);		if (!error && isreg && stat(outfile, &osb) == 0) {			if (!force && !decomp && osb.st_size >= sb.st_size) {				if (verbose > 0)					fprintf(stderr, "file would grow; "						     "left unmodified\n");				error = 1;				rc = rc? rc : 2;			} else {				setfile(outfile, &sb);				if (unlink(infile) && verbose >= 0)					warn("input: %s", infile);				if (verbose > 0) {					u_int ratio;					ratio = (1000*osb.st_size)/sb.st_size;					fprintf(stderr, "%u", ratio / 10);					if (ratio % 10)						fprintf(stderr, ".%u",						        ratio % 10);					fputc('%', stderr);					fputc(' ', stderr);				}			}		}		if (error && oreg && unlink(outfile) && errno != ENOENT &&		    verbose >= 0) {			if (force) {				warn("output: %s", outfile);				rc = 1;			} else				err(1, "output: %s", outfile);		} else if (!error && verbose > 0)			fputs("OK\n", stderr);		outfile[0] = '\0';		if (*argv != NULL)			argv++;	} while (*argv != NULL);	exit(rc);}