[BusyBox] [PATCH] dd: allow skip option when input is a tty

Jim Treadway jim at stardot-tech.com
Tue Jun 18 12:57:03 UTC 2002


The following patch (against the development CVS branch) implements the
skip option for dd when reading from a tty (which is useful for removing
fixed-length Content-Type headers from CGI programs, for example).

I didn't add support for seek when output is a tty since I don't think the 
"standard" dd does that.  Also, I just silently ignored errors on the 
assumption that the later call(s) to safe_read would do the right thing. 
;)

Jim

--- fileutils/dd.c	27 Apr 2002 01:31:43 -0000	1.49
+++ fileutils/dd.c	18 Jun 2002 18:54:32 -0000
@@ -124,7 +124,11 @@
 	}
 
 	if (skip) {
-		if (lseek(ifd, skip * bs, SEEK_CUR) < 0)
+		if (isatty(ifd)) {
+			for (i = 0; i < skip * bs; i++)
+				if (safe_read(ifd, buf, 1) != 1)
+					break;
+		} else if (lseek(ifd, skip * bs, SEEK_CUR) < 0)
 			perror_msg_and_die("%s", infile);
 	}
 





More information about the busybox mailing list