summaryrefslogtreecommitdiff
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
parent0053ea1ec07244c518f920955634137f260e7029 (diff)
parent70b0c0f1ee040b3ca771450952886dbc32b3cbdf (diff)
Merge branch 'feature/upstream' into develop
-rw-r--r--.gitignore1
-rw-r--r--config.h.in3
-rwxr-xr-xconfigure26
-rw-r--r--configure.ac4
-rw-r--r--doc/changelog.rst12
-rw-r--r--src/io.c15
6 files changed, 47 insertions, 14 deletions
diff --git a/.gitignore b/.gitignore
index eeb7940..f79120e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ Makefile.in
/build-aux/
/config.*
/configure
+/configure~
/libtool
stamp-h1
diff --git a/config.h.in b/config.h.in
index 207279f..f930a3c 100644
--- a/config.h.in
+++ b/config.h.in
@@ -33,6 +33,9 @@
/* Define to 1 if you have the `pipe' function. */
#undef HAVE_PIPE
+/* Define to 1 if you have the `posix_fadvise' function. */
+#undef HAVE_POSIX_FADVISE
+
/* Define to 1 if you have the `setgid' function. */
#undef HAVE_SETGID
diff --git a/configure b/configure
index 7287943..d40d681 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.71 for libHX 4.7.
+# Generated by GNU Autoconf 2.71 for libHX 4.8.
#
#
# Copyright (C) 1992-1996, 1998-2017, 2020-2021 Free Software Foundation,
@@ -618,8 +618,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='libHX'
PACKAGE_TARNAME='libhx'
-PACKAGE_VERSION='4.7'
-PACKAGE_STRING='libHX 4.7'
+PACKAGE_VERSION='4.8'
+PACKAGE_STRING='libHX 4.8'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''
@@ -1375,7 +1375,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures libHX 4.7 to adapt to many kinds of systems.
+\`configure' configures libHX 4.8 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1446,7 +1446,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of libHX 4.7:";;
+ short | recursive ) echo "Configuration of libHX 4.8:";;
esac
cat <<\_ACEOF
@@ -1561,7 +1561,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-libHX configure 4.7
+libHX configure 4.8
generated by GNU Autoconf 2.71
Copyright (C) 2021 Free Software Foundation, Inc.
@@ -2195,7 +2195,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by libHX $as_me 4.7, which was
+It was created by libHX $as_me 4.8, which was
generated by GNU Autoconf 2.71. Invocation command line was
$ $0$ac_configure_args_raw
@@ -3684,7 +3684,7 @@ fi
# Define the identity of the package.
PACKAGE='libhx'
- VERSION='4.7'
+ VERSION='4.8'
printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h
@@ -18171,6 +18171,12 @@ then :
printf "%s\n" "#define HAVE_PIPE 1" >>confdefs.h
fi
+ac_fn_c_check_func "$LINENO" "posix_fadvise" "ac_cv_func_posix_fadvise"
+if test "x$ac_cv_func_posix_fadvise" = xyes
+then :
+ printf "%s\n" "#define HAVE_POSIX_FADVISE 1" >>confdefs.h
+
+fi
ac_fn_c_check_func "$LINENO" "getegid" "ac_cv_func_getegid"
if test "x$ac_cv_func_getegid" = xyes
@@ -18759,7 +18765,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by libHX $as_me 4.7, which was
+This file was extended by libHX $as_me 4.8, which was
generated by GNU Autoconf 2.71. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -18827,7 +18833,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config='$ac_cs_config_escaped'
ac_cs_version="\\
-libHX config.status 4.7
+libHX config.status 4.8
configured by $0, generated by GNU Autoconf 2.71,
with options \\"\$ac_cs_config\\"
diff --git a/configure.ac b/configure.ac
index 67ef049..6e709e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([libHX], [4.7])
+AC_INIT([libHX], [4.8])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
@@ -124,7 +124,7 @@ AC_CHECK_MEMBERS(
#include <sys/time.h>
#include <time.h>
])
-AC_CHECK_FUNCS([fork execv execvp pipe])
+AC_CHECK_FUNCS([fork execv execvp pipe posix_fadvise])
AC_CHECK_FUNCS([getegid geteuid getpid getppid])
AC_CHECK_FUNCS([initgroups setgid])
diff --git a/doc/changelog.rst b/doc/changelog.rst
index 16b92fd..1894bf5 100644
--- a/doc/changelog.rst
+++ b/doc/changelog.rst
@@ -1,3 +1,15 @@
+v4.8 (2022-12-03)
+=================
+
+Enhancements:
+
+* io: call posix_fadvise when slurping files
+
+Fixes:
+
+* io: fix garbling of slurped data when read from an unknown-size source
+
+
v4.7 (2022-10-21)
=================
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;