err(1, infile);
err(1, "%s", infile);
struct compressor *check_method __P((int, const char *));struct stat sb, osb;intmain(argc, argv)	int argc;	char *argv[];{	int ch, bits, cat, decomp, error;	struct compressor *method;	int exists, isreg, oreg;	char *infile, outfile[MAXPATHLEN+4], suffix[16];	char *p;	int rc = 0;	bits = cat = decomp = 0;	p = __progname;	if (p[0] == 'g') {		method = M_DEFLATE;		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");	}	outfile[0] = '\0';	while ((ch = getopt(argc, argv, "0123456789b:cdfghlnOo:qStv")) != -1)		switch(ch) {		case '0':		case '1':		case '2':		case '3':		case '4':		case '5':		case '6':		case '7':		case '8':		case '9':			method = M_DEFLATE;			bits = ch - '0';			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;			break;		case 'l':			list++;			break;		case 'L':			fputs(copyright, stderr);		case 'n':			nosave++;			break;		case 'N':			nosave = 0;			break;		case 'O':			method = M_COMPRESS;			break;		case 'o':			strncpy(outfile, optarg, sizeof(outfile)-1);			outfile[sizeof(outfile)-1] = '\0';			break;		case 'q':			verbose = -1;			break;		case 'S':			p = suffix;			if (optarg[0] != '.')				*p++ = '.';			strncpy(p, optarg, sizeof(suffix) - (p - suffix) - 1);			break;		case 't':			testmode++;			break;		case 'v':			verbose++;			break;		case 'h':		case '?':		default:			usage();		}	argc -= optind;	argv += optind;	do {		if (*argv != NULL) {			infile = *argv;			if (outfile[0] == '\0') {				if (!decomp && !cat && outfile[0] == '\0') {					int len;					char *p;					snprintf(outfile, sizeof(outfile),						"%s%s", infile,						method->suffix);					len = strlen(outfile);					if (len > MAXPATHLEN) {						errx(1, "pathname%s too long",							method->suffix);					}										p = strrchr(outfile, '/');					if (p == NULL) p = outfile;					len = strlen(p);					if (len > NAME_MAX) {						errx(1, "filename%s too long",							method->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) {						int l =	min(sizeof(outfile),							    (p - infile));						strncpy(outfile, infile, l);						outfile[l] = '\0';					}				}			}					} 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, 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);		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 = 2;			} else {				setfile(outfile, &sb);				if (unlink(infile) && verbose >= 0)					warn("%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)			warn("%s", outfile);		else if (!error && verbose > 0)			fputs("OK\n", stderr);		outfile[0] = '\0';		if (*argv != NULL)			argv++;	} while (*argv != NULL);	return (rc);}intcompress(in, out, method, bits)	const char *in;	const char *out;	register struct compressor *method;	int bits;{	register int ifd;	int ofd;	register void *cookie;	register ssize_t nr;	u_char buf[Z_BUFSIZE];	int error;	error = 0;	cookie  = NULL;	if ((ofd = open(out, O_WRONLY|O_CREAT, S_IWUSR)) < 0) {		if (verbose >= 0)			warn("%s", out);		return -1;	}	if (method != M_COMPRESS && !force && isatty(ofd)) {		if (verbose >= 0)			warnx("%s: won't write compressed data to terminal",			      out);		return -1;	}	if ((ifd = open(in, O_RDONLY)) >= 0 &&	    (cookie = (*method->open)(ofd, "w", bits)) != NULL) {		while ((nr = read(ifd, buf, sizeof(buf))) > 0)			if ((method->write)(cookie, buf, nr) != nr) {				if (verbose >= 0)					warn("%s", out);				error++;				break;			}	}	if (ifd < 0 || close(ifd) || nr < 0) {		if (!error && verbose >= 0)			warn("%s", in);		error++;	}	if (cookie == NULL || (method->close)(cookie)) {		if (!error && verbose >= 0)			warn("%s", out);		error++;		(void) close(ofd);	}	return error? -1 : 0;}struct compressor *check_method(fd, out)	int fd;	const char *out;{	register struct compressor *method;	for (method = &c_table[0];	     method->name != NULL &&		     !(*method->check_header)(fd, &sb, out);	     method++)		;	if (method->name == NULL)		method = NULL;	return method;}