[links-list] Re: gzipped files - final

Witold Filipczyk juandon at poczta.onet.pl
Wed May 1 04:09:37 PDT 2002


Sorry, I forgot to add files to attachment.

Witek
-------------- next part --------------
--- src/protocol/file.c.orig	Wed May  1 09:11:53 2002
+++ src/protocol/file.c	Wed May  1 12:03:21 2002
@@ -44,6 +44,10 @@
 
 #define FILE_DIR_COLOR   "yellow"
 
+#ifdef HAVE_ZLIB_H
+#include <zlib.h>
+#endif
+
 #ifdef FS_UNIX_RIGHTS
 void
 setrwx(int m, unsigned char *p)
@@ -306,6 +310,9 @@
 	struct stat stt;
 	int namelen;
 	int saved_errno;
+#ifdef HAVE_ZLIB_H
+	gzFile gzh;
+#endif
 	
 	if (anonymous) {
 		abort_conn_with_state(c, S_BAD_URL);
@@ -558,7 +565,47 @@
 		head = stracpy("");
 
 	} else {
+
+#ifdef HAVE_ZLIB_H
+		const int bufsize_for_gzip = 4096;
+		int offset_for_gzip = 0;
+
+		mem_free(name);
+		gzh = gzdopen(h, "rb");
+		if (!gzh) {
+			close(h);
+			abort_conn_with_state(c, S_OUT_OF_MEM);
+			return;
+		}
+		
+		file = mem_alloc(bufsize_for_gzip + 1);
+		if (!file) {
+			fclose(gzh);
+			abort_conn_with_state(c, S_OUT_OF_MEM);
+			return;
+		}
+
+		while ((r = gzread(gzh, file + offset_for_gzip, bufsize_for_gzip)) > 0) {
+			offset_for_gzip += r;
+
+			file = mem_realloc(file, offset_for_gzip + bufsize_for_gzip + 1);
+			if (!file) {
+				fclose(gzh);
+				abort_conn_with_state(c, S_OUT_OF_MEM);
+				return;
+			}
+		}
+
+		fl = offset_for_gzip;
+		file[fl] = '\0'; /* NULL-terminate just in case */
+
+		gzclose(gzh);
+
+		head = stracpy("");
+	}
+#else
 		mem_free(name);
+
 		/* + 1 is there because of bug in Linux. Read returns -EACCES when
 		   reading 0 bytes to invalid address */
 
@@ -582,6 +629,7 @@
 		fl = stt.st_size;
 		head = stracpy("");
 	}
+#endif /* HAVE_ZLIB_H */
 	
 	if (get_cache_entry(c->url, &e)) {
 		mem_free(file);
--- configure.in.orig	Wed May  1 09:48:49 2002
+++ configure.in	Wed May  1 11:38:04 2002
@@ -113,6 +113,20 @@
 fi
 
 dnl ===================================================================
+dnl Checks for zlib, not enabled by default even if installed.
+dnl ===================================================================
+AC_ARG_WITH(zlib, [  --with-zlib             enable zlib support],
+	[ if test "$withval" = yes; then enable_zlib=yes; fi])
+AC_MSG_CHECKING([for zlib support])
+
+if test -n "$enable_zlib"; then
+	AC_CHECK_LIB(z, [gzdopen, gzread])
+	AC_CHECK_HEADERS(zlib.h, cf_result=yes, cf_result=no)
+else
+	AC_MSG_RESULT(no)
+fi
+
+dnl ===================================================================
 dnl Checks for OS/2
 dnl ===================================================================
 


More information about the links-list mailing list