Re: [PATCH 15/22] sequencer: introduce a helper to read files written by scripts
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Aug 29, 2016, 11:08 UTC
- Message-ID
- <alpine.DEB.2.20.1608291307560.129229@virtualbox>
- In-Reply-To
- <1472464060.4265.27.camel@kaarsemaker.net>
Hi Dennis,
On Mon, 29 Aug 2016, Dennis Kaarsemaker wrote:
Show 15 quoted lines
> On ma, 2016-08-29 at 10:06 +0200, Johannes Schindelin wrote:
> > + if (strbuf_read_file(buf, path, 0) < 0) {
> > + warning_errno("could not read '%s'", path);
> > + return 0;
> > + }
> > +
> > + if (buf->len > orig_len && buf->buf[buf->len - 1] == '\n') {
> > + if (--buf->len > orig_len && buf->buf[buf->len - 1]
> > == '\r')
> > + --buf->len;
> > + buf->buf[buf->len] = '\0';
> > + }
>
> Why not use open + strbuf_getline instead of hand-rolling a newline
> eradicator?Because strbuf_getline() erases the strbuf instead of appending to it (which is what we sometimes need when converting shell scripts to C).
Ciao, Dscho