summaryrefslogtreecommitdiff
path: root/src/libstddjb/slurp.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-02-21 12:05:07 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-02-21 12:05:07 +0000
commit49d8fa1058aaf23c29e074b2314492ae40d2f557 (patch)
tree393f884d5a99f984e992a0f35f1b02ac43536217 /src/libstddjb/slurp.c
parentfdffefb8032922ce7ffe4c00816072a8ff2148fc (diff)
downloadskalibs-49d8fa1058aaf23c29e074b2314492ae40d2f557.tar.xz
Types change: big pass on libstddjb and libunixonacid
libdatastruct still missing, library still not functional
Diffstat (limited to 'src/libstddjb/slurp.c')
-rw-r--r--src/libstddjb/slurp.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libstddjb/slurp.c b/src/libstddjb/slurp.c
index 553b29e..d5b3b43 100644
--- a/src/libstddjb/slurp.c
+++ b/src/libstddjb/slurp.c
@@ -1,5 +1,6 @@
/* ISC license. */
+#include <sys/types.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>
@@ -8,10 +9,11 @@
int slurp (stralloc *sa, int fd)
{
- register unsigned int salen = sa->len ;
+ size_t salen = sa->len ;
+ int wasnull = !sa->s ;
for (;;)
{
- int r ;
+ ssize_t r ;
if (!stralloc_readyplus(sa, N)) break ;
r = fd_read(fd, sa->s + sa->len, N) ;
switch (r)
@@ -25,7 +27,11 @@ int slurp (stralloc *sa, int fd)
}
}
err:
- sa->len = salen ;
- stralloc_shrink(sa) ;
+ if (wasnull) stralloc_free(sa) ;
+ else
+ {
+ sa->len = salen ;
+ stralloc_shrink(sa) ;
+ }
return 0 ;
}