From 336d9fedb35e577ce3aef12e633fcdeae04fe96d Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 25 Feb 2022 16:18:24 +0000 Subject: Don't autoshrink after slurping Signed-off-by: Laurent Bercot --- src/libstddjb/slurp.c | 19 +++++++------------ 1 file 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 + #include #include #include @@ -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 ; } -- cgit v1.2.3