summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-01-28 16:10:14 -0800
committerJunio C Hamano <gitster@pobox.com>2016-01-28 16:10:14 -0800
commitb62624b51a54325e6884c197352dc0dcef700325 (patch)
tree2a5c68bae2133bbb762253f183abcc6f00f8faef /strbuf.c
parent116a866bf50da9b893623ebb940e1c6bff7a29bc (diff)
parent1a0c8dfd89475d6bb09ddee8c019cf0ae5b3bdc2 (diff)
downloadgit-b62624b51a54325e6884c197352dc0dcef700325.tar.gz
Merge branch 'jc/strbuf-getline'
The preliminary clean-up for jc/peace-with-crlf topic. * jc/strbuf-getline: strbuf: give strbuf_getline() to the "most text friendly" variant checkout-index: there are only two possible line terminations update-index: there are only two possible line terminations check-ignore: there are only two possible line terminations check-attr: there are only two possible line terminations mktree: there are only two possible line terminations strbuf: introduce strbuf_getline_{lf,nul}() strbuf: make strbuf_getline_crlf() global strbuf: miniscule style fix
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/strbuf.c b/strbuf.c
index 38686ffb65..bab316dda8 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -512,15 +512,37 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
}
#endif
-int strbuf_getline(struct strbuf *sb, FILE *fp, int term)
+static int strbuf_getdelim(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);
+ if (sb->buf[sb->len - 1] == term)
+ strbuf_setlen(sb, sb->len - 1);
return 0;
}
+int strbuf_getline(struct strbuf *sb, FILE *fp)
+{
+ if (strbuf_getwholeline(sb, fp, '\n'))
+ return EOF;
+ if (sb->buf[sb->len - 1] == '\n') {
+ strbuf_setlen(sb, sb->len - 1);
+ if (sb->len && sb->buf[sb->len - 1] == '\r')
+ strbuf_setlen(sb, sb->len - 1);
+ }
+ return 0;
+}
+
+int strbuf_getline_lf(struct strbuf *sb, FILE *fp)
+{
+ return strbuf_getdelim(sb, fp, '\n');
+}
+
+int strbuf_getline_nul(struct strbuf *sb, FILE *fp)
+{
+ return strbuf_getdelim(sb, fp, '\0');
+}
+
int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
{
strbuf_reset(sb);