diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-12-31 10:03:36 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-12-31 10:03:36 +0100 |
commit | 70b0c0f1ee040b3ca771450952886dbc32b3cbdf (patch) | |
tree | 244ae9d2ff483079c50589f27e22a97a45ffe7df /src/io.c | |
parent | 0053ea1ec07244c518f920955634137f260e7029 (diff) | |
parent | 8132c809273676b684f426ae8c0f8b1e6f40166e (diff) |
Update upstream source from tag 'upstream/4.8'
Update to upstream version '4.8'
with Debian dir 74d8c50f51a4b7287f3c04fcedce47b00547c34b
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -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; |