1 Return-Path: <bremner@tesseract.cs.unb.ca>
\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 3830F431FAF
\r
6 for <notmuch@notmuchmail.org>; Thu, 3 Apr 2014 19:44:22 -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 hgIiWuhI4QKI for <notmuch@notmuchmail.org>;
\r
16 Thu, 3 Apr 2014 19:44:16 -0700 (PDT)
\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net
\r
18 [87.98.215.224]) (using TLSv1 with cipher AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 8A786431FBF
\r
21 for <notmuch@notmuchmail.org>; Thu, 3 Apr 2014 19:44:16 -0700 (PDT)
\r
22 Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim
\r
23 4.72) (envelope-from <bremner@tesseract.cs.unb.ca>)
\r
24 id 1WVtY7-00017W-GA; Fri, 04 Apr 2014 02:08:07 +0000
\r
25 Received: (nullmailer pid 4014 invoked by uid 1000); Thu, 03 Apr 2014
\r
27 From: David Bremner <david@tethera.net>
\r
28 To: notmuch@notmuchmail.org
\r
29 Subject: [Patch v6 2/6] util: add gz_readline
\r
30 Date: Thu, 3 Apr 2014 16:41:19 -0300
\r
31 Message-Id: <1396554083-3892-3-git-send-email-david@tethera.net>
\r
32 X-Mailer: git-send-email 1.9.0
\r
33 In-Reply-To: <1396554083-3892-1-git-send-email-david@tethera.net>
\r
34 References: <1396554083-3892-1-git-send-email-david@tethera.net>
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.13
\r
38 List-Id: "Use and development of the notmuch mail system."
\r
39 <notmuch.notmuchmail.org>
\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
43 List-Post: <mailto:notmuch@notmuchmail.org>
\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
47 X-List-Received-Date: Fri, 04 Apr 2014 02:44:22 -0000
\r
49 The idea is to provide a more or less drop in replacement for readline
\r
50 to read from zlib/gzip streams. Take the opportunity to replace
\r
53 util/Makefile.local | 2 +-
\r
54 util/util.h | 12 +++++++++
\r
55 util/zlib-extra.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
56 util/zlib-extra.h | 11 ++++++++
\r
57 4 files changed, 101 insertions(+), 1 deletion(-)
\r
58 create mode 100644 util/util.h
\r
59 create mode 100644 util/zlib-extra.c
\r
60 create mode 100644 util/zlib-extra.h
\r
62 diff --git a/util/Makefile.local b/util/Makefile.local
\r
63 index 29c0ce6..e2a5b65 100644
\r
64 --- a/util/Makefile.local
\r
65 +++ b/util/Makefile.local
\r
66 @@ -4,7 +4,7 @@ dir := util
\r
67 extra_cflags += -I$(srcdir)/$(dir)
\r
69 libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \
\r
70 - $(dir)/string-util.c $(dir)/talloc-extra.c
\r
71 + $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c
\r
73 libutil_modules := $(libutil_c_srcs:.c=.o)
\r
75 diff --git a/util/util.h b/util/util.h
\r
76 new file mode 100644
\r
77 index 0000000..8663cfc
\r
84 +typedef enum util_status {
\r
87 + UTIL_OUT_OF_MEMORY,
\r
93 diff --git a/util/zlib-extra.c b/util/zlib-extra.c
\r
94 new file mode 100644
\r
95 index 0000000..922ab52
\r
97 +++ b/util/zlib-extra.c
\r
99 +/* zlib-extra.c - Extra or enhanced routines for compressed I/O.
\r
101 + * Copyright (c) 2014 David Bremner
\r
103 + * This program is free software: you can redistribute it and/or modify
\r
104 + * it under the terms of the GNU General Public License as published by
\r
105 + * the Free Software Foundation, either version 3 of the License, or
\r
106 + * (at your option) any later version.
\r
108 + * This program is distributed in the hope that it will be useful,
\r
109 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
110 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
111 + * GNU General Public License for more details.
\r
113 + * You should have received a copy of the GNU General Public License
\r
114 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
116 + * Author: David Bremner <david@tethera.net>
\r
119 +#include "zlib-extra.h"
\r
120 +#include <talloc.h>
\r
121 +#include <stdio.h>
\r
122 +#include <string.h>
\r
124 +/* mimic POSIX/glibc getline, but on a zlib gzFile stream, and using talloc */
\r
126 +gz_getline (void *talloc_ctx, char **bufptr, ssize_t *bytes_read, gzFile stream)
\r
128 + char *buf = *bufptr;
\r
129 + unsigned int len;
\r
130 + size_t offset = 0;
\r
133 + len = talloc_array_length (buf);
\r
135 + /* same as getdelim from gnulib */
\r
137 + buf = talloc_array (talloc_ctx, char, len);
\r
139 + return UTIL_OUT_OF_MEMORY;
\r
143 + if (! gzgets (stream, buf + offset, len - offset)) {
\r
144 + /* Null indicates EOF or error */
\r
145 + int zlib_status = 0;
\r
146 + (void) gzerror (stream, &zlib_status);
\r
147 + switch (zlib_status) {
\r
149 + /* no data read before EOF */
\r
155 + return UTIL_FILE;
\r
157 + return UTIL_ERROR;
\r
161 + offset += strlen (buf + offset);
\r
163 + if (buf[offset - 1] == '\n')
\r
167 + buf = talloc_realloc (talloc_ctx, buf, char, len);
\r
169 + return UTIL_OUT_OF_MEMORY;
\r
173 + *bytes_read = offset;
\r
174 + return UTIL_SUCCESS;
\r
176 diff --git a/util/zlib-extra.h b/util/zlib-extra.h
\r
177 new file mode 100644
\r
178 index 0000000..ed67115
\r
180 +++ b/util/zlib-extra.h
\r
182 +#ifndef _ZLIB_EXTRA_H
\r
183 +#define _ZLIB_EXTRA_H
\r
188 +/* Like getline, but read from a gzFile. Allocation is with talloc */
\r
190 +gz_getline (void *ctx, char **lineptr, ssize_t *bytes_read, gzFile stream);
\r