summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-08-08 09:39:15 +0000
committerLaurent Bercot <ska@appnovation.com>2023-08-08 09:39:15 +0000
commit1f2d5f95684e93f8523e369ef1fed7a75c444082 (patch)
treef8cc1dd4b1378490386def2e0571561fab10b275 /src
parent687b52b09b10a501d21f168b45a4e24fd8bdf65e (diff)
downloadskalibs-1f2d5f95684e93f8523e369ef1fed7a75c444082.tar.xz
Fix back slurpn
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/libstddjb/slurpn.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/src/libstddjb/slurpn.c b/src/libstddjb/slurpn.c
index ee5157f..317e300 100644
--- a/src/libstddjb/slurpn.c
+++ b/src/libstddjb/slurpn.c
@@ -11,25 +11,18 @@
int slurpn (int fd, stralloc *sa, size_t max)
{
- size_t sabase = sa->len ;
- int wasnull = !sa->s ;
for (;;)
{
ssize_t r ;
- size_t n = max && sa->len - sabase + N > max ? max - (sa->len - sabase) : N ;
- if (!n) { errno = ENOBUFS ; goto err ; }
+ size_t n = max && sa->len + N > max ? max - sa->len : N ;
+ if (!n) return (errno = ENOBUFS, 0) ;
if (!stralloc_readyplus(sa, n)) break ;
r = fd_read(fd, sa->s + sa->len, n) ;
switch (r)
{
- case -1 : goto err ;
+ case -1 : return 0 ;
case 0 : return 1 ;
default : sa->len += r ;
}
}
-
-err:
- if (wasnull) stralloc_free(sa) ;
- else sa->len = sabase ;
- return 0 ;
}