commit 336d9fedb35e577ce3aef12e633fcdeae04fe96d
parent e093317ded6ea3543ebd2f8aabd2d2b2b7fc21f0
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date: Fri, 25 Feb 2022 16:18:24 +0000
Don't autoshrink after slurping
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat:
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/src/libstddjb/slurp.c b/src/libstddjb/slurp.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <sys/types.h>
+
#include <skalibs/allreadwrite.h>
#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>
@@ -9,7 +10,7 @@
int slurp (stralloc *sa, int fd)
{
- size_t salen = sa->len ;
+ size_t sabase = sa->len ;
int wasnull = !sa->s ;
for (;;)
{
@@ -18,20 +19,14 @@ int slurp (stralloc *sa, int fd)
r = fd_read(fd, sa->s + sa->len, N) ;
switch (r)
{
- case -1: goto err ;
- case 0:
- stralloc_shrink(sa) ;
- return 1 ;
- default:
- sa->len += r ;
+ case -1 : goto err ;
+ case 0 : return 1 ;
+ default : sa->len += r ;
}
}
+
err:
if (wasnull) stralloc_free(sa) ;
- else
- {
- sa->len = salen ;
- stralloc_shrink(sa) ;
- }
+ else sa->len = sabase ;
return 0 ;
}