[BusyBox-cvs] busybox/archival/libunarchive seek_by_char.c,1.1,1.2

Glenn McGrath bug1 at busybox.net
Fri Nov 14 08:26:31 UTC 2003


Update of /var/cvs/busybox/archival/libunarchive
In directory winder:/tmp/cvs-serv9659/archival/libunarchive

Modified Files:
	seek_by_char.c 
Log Message:
Read in blocks rather than one char at a time, greatly improves speed


Index: seek_by_char.c
===================================================================
RCS file: /var/cvs/busybox/archival/libunarchive/seek_by_char.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- seek_by_char.c	3 Nov 2002 14:05:08 -0000	1.1
+++ seek_by_char.c	14 Nov 2003 08:26:25 -0000	1.2
@@ -14,12 +14,31 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#include <stdlib.h>
+
 #include "unarchive.h"
+#include "busybox.h"
 
-extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int amount)
+/*	If we are reading through a pipe(), or from stdin then we cant lseek,
+ *  we must read and discard the data to skip over it.
+ *
+ *  TODO: rename to seek_by_read
+ */
+extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int jump_size)
 {
-	unsigned int i;
-	for (i = 0; i < amount; i++) {
-		archive_xread_char(archive_handle);
+	unsigned int remaining = jump_size;
+	unsigned int read_amount;
+	RESERVE_CONFIG_BUFFER(buf, BUFSIZ);
+
+	while (remaining > 0) {
+		if (remaining > BUFSIZ) {
+			read_amount = BUFSIZ;
+		} else {
+			read_amount = remaining;
+		}
+		read_amount = archive_xread(archive_handle, buf, read_amount);
+		remaining -= read_amount;
 	}
+
+	RELEASE_CONFIG_BUFFER(buf);
 }




More information about the busybox-cvs mailing list