[BusyBox-cvs] busybox.stable gzip.c,1.52,1.53

Erik Andersen andersen at codepoet.org
Tue Jan 14 18:28:24 UTC 2003


Update of /var/cvs/busybox.stable
In directory winder:/tmp/cvs-serv19474

Modified Files:
	gzip.c 
Log Message:
Apply last_patch74 from vodz to fix gzip behavior when used
with pipes.  i.e. dd if=/dev/fd0 | gzip | dd of=fd.img


Index: gzip.c
===================================================================
RCS file: /var/cvs/busybox.stable/gzip.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- gzip.c	28 Feb 2002 03:54:37 -0000	1.52
+++ gzip.c	14 Jan 2003 18:28:21 -0000	1.53
@@ -324,8 +324,6 @@
 static int part_nb;					/* number of parts in .gz file */
 static long time_stamp;				/* original time stamp (modification time) */
 static long ifile_size;				/* input file size, -1 for devices (debug only) */
-static char z_suffix[MAX_SUFFIX + 1];	/* default suffix (can be set with --suffix) */
-static int z_len;						/* strlen(z_suffix) */
 
 static char ifname[MAX_PATH_LEN];		/* input file name */
 static char ofname[MAX_PATH_LEN];		/* output file name */
@@ -1219,10 +1217,8 @@
 	struct stat statBuf;
 	char *delFileName;
 	int tostdout = 0;
-	int fromstdin = 0;
 	int force = 0;
 	int opt;
-	int file_count;
 
 	while ((opt = getopt(argc, argv, "cf123456789dq")) != -1) {
 		switch (opt) {
@@ -1247,12 +1243,16 @@
 			show_usage();
 		}
 	}
-	if ((optind == argc) || (strcmp(argv[optind], "-") == 0)) {
-		fromstdin = 1;
-		tostdout = 1;
+	if (optind == argc) {
+		optind--;
+		argv[optind] = "-";
 	}
 
-	if (isatty(fileno(stdout)) && tostdout==1 && force==0)
+	for(opt = optind; opt < argc; opt++)
+		if (strcmp(argv[opt], "-") == 0)
+			tostdout |= 2;
+
+	if (tostdout && force==0 && isatty(fileno(stdout)))
 		error_msg_and_die( "compressed data not written to terminal. Use -f to force it.");
 
 	foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
@@ -1270,10 +1270,6 @@
 	}
 #endif
 
-	file_count = argc - optind;
-	strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix) - 1);
-	z_len = strlen(z_suffix);
-
 	/* Allocate all global buffers (for DYN_ALLOC option) */
 	ALLOC(uch, inbuf, INBUFSIZ + INBUF_EXTRA);
 	ALLOC(uch, outbuf, OUTBUFSIZ + OUTBUF_EXTRA);
@@ -1281,17 +1277,16 @@
 	ALLOC(uch, window, 2L * WSIZE);
 	ALLOC(ush, tab_prefix, 1L << BITS);
 
-	if (file_count != 0) {
 		while (optind < argc) {
-
-			if (fromstdin == 1) {
+		if (strcmp(argv[optind++], "-") == 0) {
 				strcpy(ofname, "stdin");
 
 				inFileNum = fileno(stdin);
 				time_stamp = 0;			/* time unknown by default */
 				ifile_size = -1L;		/* convention for unknown size */
-				optind++;
+			tostdout |= 2;
 			} else {
+			tostdout &= ~2;
 				/* Open up the input file */
 				strncpy(ifname, argv[optind++], MAX_PATH_LEN);
 
@@ -1307,7 +1302,7 @@
 			}
 
 
-			if (tostdout == 1) {
+		if (tostdout) {
 				/* And get to work */
 				strcpy(ofname, "stdout");
 				outFileNum = fileno(stdout);
@@ -1353,7 +1348,6 @@
 					perror_msg_and_die("%s", delFileName);
 			}
 		}      /* while () */
-	}      /* if ()    */
 
 	return(exit_code);
 }




More information about the busybox-cvs mailing list