* of the GNU Lesser General Public License.
*/
-#include "ucw/lib.h"
-#include "ucw/fastbuf.h"
-#include "ucw/mempool.h"
-#include "ucw/bbuf.h"
+#include <ucw/lib.h>
+#include <ucw/fastbuf.h>
+#include <ucw/mempool.h>
+#include <ucw/bbuf.h>
char * /* Non-standard */
bgets(struct fastbuf *f, char *b, uns l)
*b++ = v;
}
if (unlikely(cnt == l))
- die("%s: Line too long", f->name);
+ bthrow(f, "toolong", "%s: Line too long", f->name);
l -= cnt;
bdirect_read_commit(f, src);
src_len = bdirect_read_prepare(f, &src);
if (cnt == buf_len)
{
if (unlikely(len == limit))
- die("%s: Line too long", f->name);
+ bthrow(f, "toolong", "%s: Line too long", f->name);
bb_do_grow(bb, len + 1);
buf = bb->ptr + len;
buf_len = MIN(bb->len, limit) - len;
#undef BLOCK_SIZE
}
-void
-bgets_stk_init(struct bgets_stk_struct *s)
-{
- s->src_len = bdirect_read_prepare(s->f, &s->src);
- if (!s->src_len)
- {
- s->cur_buf = NULL;
- s->cur_len = 0;
- }
- else
- {
- s->old_buf = NULL;
- s->cur_len = 256;
- }
-}
-
-void
-bgets_stk_step(struct bgets_stk_struct *s)
-{
- byte *buf = s->cur_buf;
- uns buf_len = s->cur_len;
- if (s->old_buf)
- {
- memcpy( s->cur_buf, s->old_buf, s->old_len);
- buf += s->old_len;
- buf_len -= s->old_len;
- }
- do
- {
- uns cnt = MIN(s->src_len, buf_len);
- for (uns i = cnt; i--;)
- {
- byte v = *s->src++;
- if (v == '\n')
- {
- bdirect_read_commit(s->f, s->src);
- goto exit;
- }
- *buf++ = v;
- }
- if (cnt == s->src_len)
- {
- bdirect_read_commit(s->f, s->src);
- s->src_len = bdirect_read_prepare(s->f, &s->src);
- }
- else
- s->src_len -= cnt;
- if (cnt == buf_len)
- {
- s->old_len = s->cur_len;
- s->old_buf = s->cur_buf;
- s->cur_len *= 2;
- return;
- }
- else
- buf_len -= cnt;
- }
- while (s->src_len);
-exit:
- *buf = 0;
- s->cur_len = 0;
-}
-
char *
bgets0(struct fastbuf *f, char *b, uns l)
{
b++;
}
if (unlikely(cnt == l))
- die("%s: Line too long", f->name);
+ bthrow(f, "toolong", "%s: Line too long", f->name);
l -= cnt;
bdirect_read_commit(f, src);
src_len = bdirect_read_prepare(f, &src);