summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2022-02-25 16:18:24 +0000
committerLaurent Bercot <ska@appnovation.com>2022-02-25 16:18:24 +0000
commit336d9fedb35e577ce3aef12e633fcdeae04fe96d (patch)
treec838f737ddc12f528477497094a35c76156f1e94 /src
parente093317ded6ea3543ebd2f8aabd2d2b2b7fc21f0 (diff)
downloadskalibs-336d9fedb35e577ce3aef12e633fcdeae04fe96d.tar.xz
Don't autoshrink after slurping
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/libstddjb/slurp.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/libstddjb/slurp.c b/src/libstddjb/slurp.c
index d5b3b43..7437142 100644
--- 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 ;
}