unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob cda369fdf74a50f3c6cf33dec47fe057c4392f86 1566 bytes (raw)
name: util/zlib-extra.c 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
/* zlib-extra.c -  Extra or enhanced routines for compressed I/O.
 *
 * Copyright (c) 2014 David Bremner
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/ .
 *
 * Author: David Bremner <david@tethera.net>
 */

#include "zlib-extra.h"
#include <talloc.h>
#include <stdio.h>
#include <string.h>

/* mimic POSIX/glibc getline, but on a zlib gzFile stream, and using talloc */
ssize_t
gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream) {

    size_t len=*n;
    char *buf = *lineptr;
    size_t offset = 0;

    if (len == 0 || buf == NULL) {
	/* XXX arbitrary choice of initial size */
	len = BUFSIZ;
	buf = talloc_size (ctx, len);
    }

    while (1) {

	if (!gzgets (stream, buf + offset, len))
	    return -1;

	/* XXX wasted effort re-counting length of whole line */
	offset = strlen (buf);

	if ( buf[offset-1] == '\n' )
	    break;

	len *= 2;
	buf = talloc_realloc (ctx, buf, char, len);

    }

    *lineptr = buf;
    *n = len;
    return offset;
}

debug log:

solving cda369f ...
found cda369f in https://yhetil.org/notmuch/1396116992-29640-3-git-send-email-david@tethera.net/

applying [1/1] https://yhetil.org/notmuch/1396116992-29640-3-git-send-email-david@tethera.net/
diff --git a/util/zlib-extra.c b/util/zlib-extra.c
new file mode 100644
index 0000000..cda369f

Checking patch util/zlib-extra.c...
Applied patch util/zlib-extra.c cleanly.

index at:
100644 cda369fdf74a50f3c6cf33dec47fe057c4392f86	util/zlib-extra.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).