summaryrefslogtreecommitdiffstats
path: root/getln2.c
diff options
context:
space:
mode:
Diffstat (limited to 'getln2.c')
-rw-r--r--getln2.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/getln2.c b/getln2.c
new file mode 100644
index 0000000..9e576e9
--- /dev/null
+++ b/getln2.c
@@ -0,0 +1,31 @@
1#include "substdio.h"
2#include "stralloc.h"
3#include "byte.h"
4#include "getln.h"
5
6int getln2(ss,sa,cont,clen,sep)
7register substdio *ss;
8register stralloc *sa;
9/*@out@*/char **cont;
10/*@out@*/unsigned int *clen;
11int sep;
12{
13 register char *x;
14 register unsigned int i;
15 int n;
16
17 if (!stralloc_ready(sa,0)) return -1;
18 sa->len = 0;
19
20 for (;;) {
21 n = substdio_feed(ss);
22 if (n < 0) return -1;
23 if (n == 0) { *clen = 0; return 0; }
24 x = substdio_PEEK(ss);
25 i = byte_chr(x,n,sep);
26 if (i < n) { substdio_SEEK(ss,*clen = i + 1); *cont = x; return 0; }
27 if (!stralloc_readyplus(sa,n)) return -1;
28 i = sa->len;
29 sa->len = i + substdio_get(ss,sa->s + i,n);
30 }
31}