-byte *bgets(struct fastbuf *f, byte *b, uns l); /* Non-std */
-int bgets_nodie(struct fastbuf *f, byte *b, uns l);
-byte *bgets0(struct fastbuf *f, byte *b, uns l);
+/*
+ * Functions for reading of strings:
+ *
+ * bgets() reads a line, strip the trailing '\n' and return a pointer
+ * to the terminating 0 or NULL on EOF. Dies if the line is too long.
+ * bgets0() does the same for 0-terminated strings.
+ * bgets_nodie() a variant of bgets() which returns either the length of the
+ * string (excluding the terminator) or -1 if the line does not fit
+ * in the buffer. In such cases, it returns after reading exactly `l'
+ * bytes of input.
+ * bgets_bb() a variant of bgets() which allocates the string in a growing buffer
+ * bgets_mp() the same, but in a mempool
+ * bgets_stk() the same, but on the stack by alloca()
+ */
+
+char *bgets(struct fastbuf *f, char *b, uns l);
+char *bgets0(struct fastbuf *f, char *b, uns l);
+int bgets_nodie(struct fastbuf *f, char *b, uns l);
+
+struct mempool;
+struct bb_t;
+uns bgets_bb(struct fastbuf *f, struct bb_t *b, uns limit);
+char *bgets_mp(struct fastbuf *f, struct mempool *mp);
+
+struct bgets_stk_struct {
+ struct fastbuf *f;
+ byte *old_buf, *cur_buf, *src;
+ uns old_len, cur_len, src_len;
+};
+void bgets_stk_init(struct bgets_stk_struct *s);
+void bgets_stk_step(struct bgets_stk_struct *s);
+#define bgets_stk(fb) ({ struct bgets_stk_struct _s; _s.f = (fb); for (bgets_stk_init(&_s); _s.cur_len; _s.cur_buf = alloca(_s.cur_len), bgets_stk_step(&_s)); _s.cur_buf; })