Thread (8 messages) 8 messages, 4 authors, 2022-08-11

Re: [PATCH 2/2] builtin/cat-file.c: support NUL-delimited input with `-z`

From: Chris Torek <hidden>
Date: 2022-07-22 23:42:11

On Fri, Jul 22, 2022 at 4:34 PM Taylor Blau [off-list ref] wrote:
The refactoring here is slightly unfortunate, since we turn loops like:

    while (strbuf_getline(&buf, stdin) != EOF)

into:

    while (1) {
        int ret;
        if (opt->nul_terminated)
            ret = strbuf_getline_nul(&input, stdin);
        else
            ret = strbuf_getline(&input, stdin);

        if (ret == EOF)
            break;
    }

It's tempting to think that we could use `strbuf_getwholeline()` and
specify either `\n` or `\0` as the terminating character. ...
How about:

    int (*get)(struct strbuf *, FILE *);
    get = opt->nul_terminated ? strbuf_getline_nul : strbuf_getline;
    while (get(&buf, stdin) != EOF)

or similar?

Chris
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help