reports an error instead.
I wrote it originally for new http.c, but the required http.c changes were
going to be too extensive, so I postponed the changes and this function
is currently unused, but probably worth saving for the future.
Also optimized the existing bgets functions a bit.
int k;
k = bgetc(f);
- if (k == EOF)
+ if (k < 0)
return NULL;
while (b < e)
{
- if (k == '\n' || k == EOF)
+ if (k == '\n' || k < 0)
{
*b = 0;
return b;
die("%s: Line too long", f->name);
}
+int
+bgets_nodie(struct fastbuf *f, byte *b, uns l)
+{
+ byte *start = b;
+ byte *e = b + l - 1;
+ int k;
+
+ k = bgetc(f);
+ if (k < 0)
+ return 0;
+ while (b < e)
+ {
+ if (k == '\n' || k < 0)
+ {
+ *b++ = 0;
+ return b - start;
+ }
+ *b++ = k;
+ k = bgetc(f);
+ }
+ return -1;
+}
+
byte *
bgets0(struct fastbuf *f, byte *b, uns l)
{
int k;
k = bgetc(f);
- if (k == EOF)
+ if (k < 0)
return NULL;
while (b < e)
{
- if (!k || k == EOF)
+ if (k <= 0)
{
*b = 0;
return b;
}
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);
static inline void