summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2022-12-31 10:03:34 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2022-12-31 10:03:34 +0100
commit8132c809273676b684f426ae8c0f8b1e6f40166e (patch)
tree693cd9ad2a477a65666f22072c284036612b0f2a /src
parent532d4a24e2013262dfa41fd85c06a9715c99abf7 (diff)
New upstream version 4.8upstream/4.8
Diffstat (limited to 'src')
-rw-r--r--src/io.c15
1 files changed, 13 insertions, 2 deletions
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 <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
@@ -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;