summaryrefslogtreecommitdiff
path: root/src/libstddjb/openreadfileclose.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb/openreadfileclose.c')
-rw-r--r--src/libstddjb/openreadfileclose.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libstddjb/openreadfileclose.c b/src/libstddjb/openreadfileclose.c
index afa895a..144f264 100644
--- a/src/libstddjb/openreadfileclose.c
+++ b/src/libstddjb/openreadfileclose.c
@@ -1,6 +1,8 @@
/* ISC license. */
#include <sys/stat.h>
+#include <errno.h>
+
#include <skalibs/allreadwrite.h>
#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>
@@ -8,6 +10,7 @@
int openreadfileclose (char const *file, stralloc *sa, size_t limit)
{
size_t n ;
+ int e = errno ;
int fd = openbc_read(file) ;
if (fd < 0) return 0 ;
{
@@ -18,11 +21,14 @@ int openreadfileclose (char const *file, stralloc *sa, size_t limit)
if (limit && (limit < n)) n = limit ;
if (!stralloc_ready_tuned(sa, sa->len + n, 0, 0, 1)) goto err ;
{
- size_t r = allread(fd, sa->s + sa->len, n) ;
+ size_t r ;
+ errno = EPIPE ;
+ r = allread(fd, sa->s + sa->len, n) ;
sa->len += r ;
if (r < n) goto err ;
}
fd_close(fd) ;
+ errno = e ;
return 1 ;
err: