From 8132c809273676b684f426ae8c0f8b1e6f40166e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 31 Dec 2022 10:03:34 +0100 Subject: New upstream version 4.8 --- src/io.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/io.c b/src/io.c index b5bdc08..c797193 100644 --- a/src/io.c +++ b/src/io.c @@ -7,6 +7,9 @@ * General Public License as published by the Free Software Foundation; * either version 2.1 or (at your option) any later version. */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include #include #include @@ -694,10 +697,13 @@ EXPORT_SYMBOL char *HX_slurp_fd(int fd, size_t *outsize) if (buf == nullptr) return nullptr; ssize_t rdret; - while ((rdret = read(fd, buf, bufsize - 1 - offset)) > 0) { + while ((rdret = read(fd, buf + offset, bufsize - 1 - offset)) > 0) { offset += rdret; + /* + * Make it so that the next read call is not called + * with an exceptionally small size. + */ if (bufsize - offset >= 4095) - /* any value would work, but >=1 is not all that efficient */ continue; if (bufsize > SSIZE_MAX) /* No more doubling */ @@ -720,6 +726,11 @@ EXPORT_SYMBOL char *HX_slurp_fd(int fd, size_t *outsize) size_t fsize = sb.st_size; /* may truncate from loff_t to size_t */ if (fsize == SIZE_MAX) --fsize; +#ifdef HAVE_POSIX_FADVISE + if (fsize > 0 && posix_fadvise(fd, 0, fsize, + POSIX_FADV_SEQUENTIAL) != 0) + /* ignore */; +#endif char *buf = malloc(fsize + 1); if (buf == NULL) return NULL; -- cgit v1.2.3