Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v0.99.9l
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 45 lines (38 sloc) 0.807 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include <stdio.h>
#include <stdlib.h>
#include "strbuf.h"
#include "cache.h"

void strbuf_init(struct strbuf *sb) {
sb->buf = NULL;
sb->eof = sb->alloc = sb->len = 0;
}

static void strbuf_begin(struct strbuf *sb) {
free(sb->buf);
strbuf_init(sb);
}

static void inline strbuf_add(struct strbuf *sb, int ch) {
if (sb->alloc <= sb->len) {
sb->alloc = sb->alloc * 3 / 2 + 16;
sb->buf = xrealloc(sb->buf, sb->alloc);
}
sb->buf[sb->len++] = ch;
}

static void strbuf_end(struct strbuf *sb) {
strbuf_add(sb, 0);
}

void read_line(struct strbuf *sb, FILE *fp, int term) {
int ch;
strbuf_begin(sb);
if (feof(fp)) {
sb->eof = 1;
return;
}
while ((ch = fgetc(fp)) != EOF) {
if (ch == term)
break;
strbuf_add(sb, ch);
}
if (ch == EOF && sb->len == 0)
sb->eof = 1;
strbuf_end(sb);
}

Something went wrong with that request. Please try again.