summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2022-12-31 10:03:48 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2022-12-31 10:03:48 +0100
commit7f8b2bad48cb37d4110f4939f01707330a2b221c (patch)
tree244ae9d2ff483079c50589f27e22a97a45ffe7df /src
parent0053ea1ec07244c518f920955634137f260e7029 (diff)
parent70b0c0f1ee040b3ca771450952886dbc32b3cbdf (diff)
Merge branch 'feature/upstream' into develop
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;