diff options
author | Brandon Casey <drafnel@gmail.com> | 2009-08-04 22:31:56 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-08-05 12:13:56 -0700 |
commit | c7e4f0d78aaac33d5e3cec54cddd40439e77d16c (patch) | |
tree | 858630ef7be2bc8eb26148914c906f5f974df94b /strbuf.c | |
parent | 07a4a3b4962e1fd4e40fd877427cddd7428c1bc3 (diff) | |
download | git-c7e4f0d78aaac33d5e3cec54cddd40439e77d16c.tar.gz |
strbuf: add new function strbuf_getwholeline()
This function is just like strbuf_getline() except it retains the
line-termination character. This function will be used by the mailinfo
and mailsplit builtins which require the entire line for parsing.
Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'strbuf.c')
-rw-r--r-- | strbuf.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -322,7 +322,7 @@ int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint) return -1; } -int strbuf_getline(struct strbuf *sb, FILE *fp, int term) +int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term) { int ch; @@ -332,10 +332,10 @@ int strbuf_getline(struct strbuf *sb, FILE *fp, int term) strbuf_reset(sb); while ((ch = fgetc(fp)) != EOF) { - if (ch == term) - break; strbuf_grow(sb, 1); sb->buf[sb->len++] = ch; + if (ch == term) + break; } if (ch == EOF && sb->len == 0) return EOF; @@ -344,6 +344,15 @@ int strbuf_getline(struct strbuf *sb, FILE *fp, int term) return 0; } +int strbuf_getline(struct strbuf *sb, FILE *fp, int term) +{ + if (strbuf_getwholeline(sb, fp, term)) + return EOF; + if (sb->buf[sb->len-1] == term) + strbuf_setlen(sb, sb->len-1); + return 0; +} + int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint) { int fd, len; |