Add strbuf_read_file().

Signed-off-by: Kristian Høgsberg <krh@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Kristian Høgsberg
2007-09-17 20:06:46 -04:00
committed by Junio C Hamano
parent b4833a2c62
commit a9390b9fce
3 changed files with 19 additions and 8 deletions

View File

@ -177,3 +177,18 @@ int strbuf_getline(struct strbuf *sb, FILE *fp, int term)
sb->buf[sb->len] = '\0';
return 0;
}
int strbuf_read_file(struct strbuf *sb, const char *path)
{
int fd, len;
fd = open(path, O_RDONLY);
if (fd < 0)
return -1;
len = strbuf_read(sb, fd, 0);
close(fd);
if (len < 0)
return -1;
return len;
}