1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 15877431FD5
\r
6 for <notmuch@notmuchmail.org>; Sat, 29 Mar 2014 11:17:08 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id tNOHric-MyAQ for <notmuch@notmuchmail.org>;
\r
16 Sat, 29 Mar 2014 11:16:59 -0700 (PDT)
\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])
\r
18 (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 99710431FBC
\r
21 for <notmuch@notmuchmail.org>; Sat, 29 Mar 2014 11:16:52 -0700 (PDT)
\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)
\r
23 (envelope-from <bremner@tethera.net>)
\r
24 id 1WTxoK-0007wv-Bu; Sat, 29 Mar 2014 15:16:52 -0300
\r
25 Received: (nullmailer pid 29816 invoked by uid 1000); Sat, 29 Mar 2014
\r
27 From: David Bremner <david@tethera.net>
\r
28 To: notmuch@notmuchmail.org
\r
29 Subject: [Patch v2 2/3] util: add gzreadline
\r
30 Date: Sat, 29 Mar 2014 15:16:31 -0300
\r
31 Message-Id: <1396116992-29640-3-git-send-email-david@tethera.net>
\r
32 X-Mailer: git-send-email 1.9.0
\r
33 In-Reply-To: <1396116992-29640-1-git-send-email-david@tethera.net>
\r
34 References: <1396100785-8744-1-git-send-email-david@tethera.net>
\r
35 <1396116992-29640-1-git-send-email-david@tethera.net>
\r
36 X-BeenThere: notmuch@notmuchmail.org
\r
37 X-Mailman-Version: 2.1.13
\r
39 List-Id: "Use and development of the notmuch mail system."
\r
40 <notmuch.notmuchmail.org>
\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
42 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
44 List-Post: <mailto:notmuch@notmuchmail.org>
\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
48 X-List-Received-Date: Sat, 29 Mar 2014 18:17:08 -0000
\r
50 The idea is to provide a more or less drop in replacement for readline
\r
51 to read from zlib/gzip streams. Take the opportunity to replace
\r
54 util/Makefile.local | 2 +-
\r
55 util/zlib-extra.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
56 util/zlib-extra.h | 10 +++++++++
\r
57 3 files changed, 70 insertions(+), 1 deletion(-)
\r
58 create mode 100644 util/zlib-extra.c
\r
59 create mode 100644 util/zlib-extra.h
\r
61 diff --git a/util/Makefile.local b/util/Makefile.local
\r
62 index 29c0ce6..e2a5b65 100644
\r
63 --- a/util/Makefile.local
\r
64 +++ b/util/Makefile.local
\r
65 @@ -4,7 +4,7 @@ dir := util
\r
66 extra_cflags += -I$(srcdir)/$(dir)
\r
68 libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \
\r
69 - $(dir)/string-util.c $(dir)/talloc-extra.c
\r
70 + $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c
\r
72 libutil_modules := $(libutil_c_srcs:.c=.o)
\r
74 diff --git a/util/zlib-extra.c b/util/zlib-extra.c
\r
75 new file mode 100644
\r
76 index 0000000..cda369f
\r
78 +++ b/util/zlib-extra.c
\r
80 +/* zlib-extra.c - Extra or enhanced routines for compressed I/O.
\r
82 + * Copyright (c) 2014 David Bremner
\r
84 + * This program is free software: you can redistribute it and/or modify
\r
85 + * it under the terms of the GNU General Public License as published by
\r
86 + * the Free Software Foundation, either version 3 of the License, or
\r
87 + * (at your option) any later version.
\r
89 + * This program is distributed in the hope that it will be useful,
\r
90 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
91 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
92 + * GNU General Public License for more details.
\r
94 + * You should have received a copy of the GNU General Public License
\r
95 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
97 + * Author: David Bremner <david@tethera.net>
\r
100 +#include "zlib-extra.h"
\r
101 +#include <talloc.h>
\r
102 +#include <stdio.h>
\r
103 +#include <string.h>
\r
105 +/* mimic POSIX/glibc getline, but on a zlib gzFile stream, and using talloc */
\r
107 +gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream) {
\r
110 + char *buf = *lineptr;
\r
111 + size_t offset = 0;
\r
113 + if (len == 0 || buf == NULL) {
\r
114 + /* XXX arbitrary choice of initial size */
\r
116 + buf = talloc_size (ctx, len);
\r
121 + if (!gzgets (stream, buf + offset, len))
\r
124 + /* XXX wasted effort re-counting length of whole line */
\r
125 + offset = strlen (buf);
\r
127 + if ( buf[offset-1] == '\n' )
\r
131 + buf = talloc_realloc (ctx, buf, char, len);
\r
139 diff --git a/util/zlib-extra.h b/util/zlib-extra.h
\r
140 new file mode 100644
\r
141 index 0000000..c18480f
\r
143 +++ b/util/zlib-extra.h
\r
145 +#ifndef _ZLIB_EXTRA_H
\r
146 +#define _ZLIB_EXTRA_H
\r
150 +/* Like getline, but read from a gzFile. Allocation is with talloc */
\r
152 +gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream);
\r