From 8d7ea15cf2d519e6f6cae540bdaeeee7fbc82acc Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 20 Feb 2001 22:32:06 +0000 Subject: [PATCH] Added bgets0(). --- lib/fastbuf.c | 22 ++++++++++++++++++++++ lib/fastbuf.h | 1 + 2 files changed, 23 insertions(+) diff --git a/lib/fastbuf.c b/lib/fastbuf.c index 2d00bf05..00fa51bc 100644 --- a/lib/fastbuf.c +++ b/lib/fastbuf.c @@ -256,6 +256,28 @@ bgets(struct fastbuf *f, byte *b, uns l) die("%s: Line too long", f->name); } +byte * +bgets0(struct fastbuf *f, byte *b, uns l) +{ + byte *e = b + l - 1; + int k; + + k = bgetc(f); + if (k == EOF) + return NULL; + while (b < e) + { + if (!k || k == EOF) + { + *b = 0; + return b; + } + *b++ = k; + k = bgetc(f); + } + die("%s: Line too long", f->name); +} + int bdirect_read(struct fastbuf *f, byte **buf) { diff --git a/lib/fastbuf.h b/lib/fastbuf.h index 15bfed5a..d831ed36 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -306,6 +306,7 @@ static inline void bwrite(struct fastbuf *f, void *b, uns l) } byte *bgets(struct fastbuf *f, byte *b, uns l); /* Non-std */ +byte *bgets0(struct fastbuf *f, byte *b, uns l); static inline void bputs(struct fastbuf *f, byte *b) -- 2.39.2