bundle: put strbuf_readline_fd in strbuf.c with adjustments

The comment even said that it should eventually go there. While at it, match the calling convention and name of the function to the strbuf_get*line family. So it now is strbuf_getwholeline_fd. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Feb 22, 2012 at 20:34 UTC 5e8617f560968567c285bc2e9b0674f8f9d535cb
3 files changed +19 -19
bundle.c
+2 -19
@@ -23,23 +23,6 @@ static void add_to_ref_list(const unsigned char *sha1, const char *name,
23 list->nr++;
24 }
25
26 -/* Eventually this should go to strbuf.[ch] */
27 -static int strbuf_readline_fd(struct strbuf *sb, int fd)
28 -{
29 - strbuf_reset(sb);
30 -
31 - while (1) {
32 - char ch;
33 - ssize_t len = xread(fd, &ch, 1);
34 - if (len <= 0)
35 - return len;
36 - strbuf_addch(sb, ch);
37 - if (ch == '\n')
38 - break;
39 - }
40 - return 0;
41 -}
42 -
26 static int parse_bundle_header(int fd, struct bundle_header *header,
27 const char *report_path)
28 {
@@ -47,7 +30,7 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
30 int status = 0;
31
32 /* The bundle header begins with the signature */
50 - if (strbuf_readline_fd(&buf, fd) ||
33 + if (strbuf_getwholeline_fd(&buf, fd, '\n') ||
34 strcmp(buf.buf, bundle_signature)) {
35 if (report_path)
36 error("'%s' does not look like a v2 bundle file",
@@ -57,7 +40,7 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
40 }
41
42 /* The bundle header ends with an empty line */
60 - while (!strbuf_readline_fd(&buf, fd) &&
43 + while (!strbuf_getwholeline_fd(&buf, fd, '\n') &&
44 buf.len && buf.buf[0] != '\n') {
45 unsigned char sha1[20];
46 int is_prereq = 0;
strbuf.c
+16
@@ -383,6 +383,22 @@ int strbuf_getline(struct strbuf *sb, FILE *fp, int term)
383 return 0;
384 }
385
386 +int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
387 +{
388 + strbuf_reset(sb);
389 +
390 + while (1) {
391 + char ch;
392 + ssize_t len = xread(fd, &ch, 1);
393 + if (len <= 0)
394 + return EOF;
395 + strbuf_addch(sb, ch);
396 + if (ch == term)
397 + break;
398 + }
399 + return 0;
400 +}
401 +
402 int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
403 {
404 int fd, len;
strbuf.h
+1
@@ -108,6 +108,7 @@ extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
108
109 extern int strbuf_getwholeline(struct strbuf *, FILE *, int);
110 extern int strbuf_getline(struct strbuf *, FILE *, int);
111 +extern int strbuf_getwholeline_fd(struct strbuf *, int, int);
112
113 extern void stripspace(struct strbuf *buf, int skip_comments);
114 extern int launch_editor(const char *path, struct strbuf *buffer, const char *const *env);