summaryrefslogtreecommitdiff
path: root/src/libstddjb/skagetln.c
blob: 05775f6db597aba5e92d82674cc71a084035015f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* ISC license. */

#include <errno.h>
#include <skalibs/buffer.h>
#include <skalibs/stralloc.h>
#include <skalibs/skamisc.h>

int skagetln (buffer *b, stralloc *sa, char sep)
{
  unsigned int start = sa->len ;
  for (;;)
  {
    register int r = skagetln_nofill(b, sa, sep) ;
    if (r) return r ;
    r = buffer_fill(b) ;
    if (r < 0) return r ;
    if (!r) return (sa->s && (sa->len > start)) ? (errno = EPIPE, -1) : 0 ;
  }
}