--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 15877431FD5\r
+ for <notmuch@notmuchmail.org>; Sat, 29 Mar 2014 11:17:08 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id tNOHric-MyAQ for <notmuch@notmuchmail.org>;\r
+ Sat, 29 Mar 2014 11:16:59 -0700 (PDT)\r
+Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 99710431FBC\r
+ for <notmuch@notmuchmail.org>; Sat, 29 Mar 2014 11:16:52 -0700 (PDT)\r
+Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1WTxoK-0007wv-Bu; Sat, 29 Mar 2014 15:16:52 -0300\r
+Received: (nullmailer pid 29816 invoked by uid 1000); Sat, 29 Mar 2014\r
+ 18:16:38 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v2 2/3] util: add gzreadline\r
+Date: Sat, 29 Mar 2014 15:16:31 -0300\r
+Message-Id: <1396116992-29640-3-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.9.0\r
+In-Reply-To: <1396116992-29640-1-git-send-email-david@tethera.net>\r
+References: <1396100785-8744-1-git-send-email-david@tethera.net>\r
+ <1396116992-29640-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 29 Mar 2014 18:17:08 -0000\r
+\r
+The idea is to provide a more or less drop in replacement for readline\r
+to read from zlib/gzip streams. Take the opportunity to replace\r
+malloc with talloc.\r
+---\r
+ util/Makefile.local | 2 +-\r
+ util/zlib-extra.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ util/zlib-extra.h | 10 +++++++++\r
+ 3 files changed, 70 insertions(+), 1 deletion(-)\r
+ create mode 100644 util/zlib-extra.c\r
+ create mode 100644 util/zlib-extra.h\r
+\r
+diff --git a/util/Makefile.local b/util/Makefile.local\r
+index 29c0ce6..e2a5b65 100644\r
+--- a/util/Makefile.local\r
++++ b/util/Makefile.local\r
+@@ -4,7 +4,7 @@ dir := util\r
+ extra_cflags += -I$(srcdir)/$(dir)\r
+ \r
+ libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \\r
+- $(dir)/string-util.c $(dir)/talloc-extra.c\r
++ $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c\r
+ \r
+ libutil_modules := $(libutil_c_srcs:.c=.o)\r
+ \r
+diff --git a/util/zlib-extra.c b/util/zlib-extra.c\r
+new file mode 100644\r
+index 0000000..cda369f\r
+--- /dev/null\r
++++ b/util/zlib-extra.c\r
+@@ -0,0 +1,59 @@\r
++/* zlib-extra.c - Extra or enhanced routines for compressed I/O.\r
++ *\r
++ * Copyright (c) 2014 David Bremner\r
++ *\r
++ * This program is free software: you can redistribute it and/or modify\r
++ * it under the terms of the GNU General Public License as published by\r
++ * the Free Software Foundation, either version 3 of the License, or\r
++ * (at your option) any later version.\r
++ *\r
++ * This program is distributed in the hope that it will be useful,\r
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
++ * GNU General Public License for more details.\r
++ *\r
++ * You should have received a copy of the GNU General Public License\r
++ * along with this program. If not, see http://www.gnu.org/licenses/ .\r
++ *\r
++ * Author: David Bremner <david@tethera.net>\r
++ */\r
++\r
++#include "zlib-extra.h"\r
++#include <talloc.h>\r
++#include <stdio.h>\r
++#include <string.h>\r
++\r
++/* mimic POSIX/glibc getline, but on a zlib gzFile stream, and using talloc */\r
++ssize_t\r
++gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream) {\r
++\r
++ size_t len=*n;\r
++ char *buf = *lineptr;\r
++ size_t offset = 0;\r
++\r
++ if (len == 0 || buf == NULL) {\r
++ /* XXX arbitrary choice of initial size */\r
++ len = BUFSIZ;\r
++ buf = talloc_size (ctx, len);\r
++ }\r
++\r
++ while (1) {\r
++\r
++ if (!gzgets (stream, buf + offset, len))\r
++ return -1;\r
++\r
++ /* XXX wasted effort re-counting length of whole line */\r
++ offset = strlen (buf);\r
++\r
++ if ( buf[offset-1] == '\n' )\r
++ break;\r
++\r
++ len *= 2;\r
++ buf = talloc_realloc (ctx, buf, char, len);\r
++\r
++ }\r
++\r
++ *lineptr = buf;\r
++ *n = len;\r
++ return offset;\r
++}\r
+diff --git a/util/zlib-extra.h b/util/zlib-extra.h\r
+new file mode 100644\r
+index 0000000..c18480f\r
+--- /dev/null\r
++++ b/util/zlib-extra.h\r
+@@ -0,0 +1,10 @@\r
++#ifndef _ZLIB_EXTRA_H\r
++#define _ZLIB_EXTRA_H\r
++\r
++#include <zlib.h>\r
++\r
++/* Like getline, but read from a gzFile. Allocation is with talloc */\r
++ssize_t\r
++gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream);\r
++\r
++#endif\r
+-- \r
+1.9.0\r
+\r