diff options
| author | manuel <manuel@mausz.at> | 2013-02-04 00:08:53 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-02-04 00:08:53 +0100 |
| commit | 69aec538b456402170dc723af417ba5c05389c32 (patch) | |
| tree | e6f34c543f17c6392447ea337b2e2868212424d1 /getln2.c | |
| download | qmail-69aec538b456402170dc723af417ba5c05389c32.tar.gz qmail-69aec538b456402170dc723af417ba5c05389c32.tar.bz2 qmail-69aec538b456402170dc723af417ba5c05389c32.zip | |
qmail 1.03 import
Diffstat (limited to 'getln2.c')
| -rw-r--r-- | getln2.c | 31 |
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 | |||
| 6 | int getln2(ss,sa,cont,clen,sep) | ||
| 7 | register substdio *ss; | ||
| 8 | register stralloc *sa; | ||
| 9 | /*@out@*/char **cont; | ||
| 10 | /*@out@*/unsigned int *clen; | ||
| 11 | int 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 | } | ||
