Bug#674709: unsort: FTBFS on hurd-i386: IOV_MAX not defined
Package: unsort
Version: 1.1.2-1
Severity: important
Tags: patch
User: debian-hurd@lists.debian.org
Usertags: hurd
X-Debbugs-CC: debian-hurd@lists.debian.org
Currently unsort fails to build on hurd-i386 because the symbol
IOV_MAX (the maximum number of items that can be passed to
writev/readv) is not defined. The POSIX standard doesn't guarantee
that IOV_MAX will be defined, rather it states that it should be
omitted if the limit can't be determined at compile time or no fixed
limit exists.[1]
The attached patch uses sysconf(_SC_IOV_MAX) to query the appropriate
limit at runtime rather than relying on IOV_MAX.
[1] <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html#tag_13_23_03_01>
diff --git a/iovec.c b/iovec.c
index 8ad94bf..7273c18 100644
--- a/iovec.c
+++ b/iovec.c
@@ -21,6 +21,7 @@
*****************************************************************************/
+#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
@@ -41,14 +42,20 @@ struct iovec_const {
size_t iov_len;
};
-static uint32_t writev_max = IOV_MAX;
-
void writev_all(int fd, struct iovec *iov, uint32_t count) {
ssize_t r, len;
+ uint32_t writev_max;
+ long sc_iovmax;
if(!count)
return;
+ errno = 0;
+ if ((sc_iovmax = sysconf(_SC_IOV_MAX)) == -1)
+ writev_max = errno ? _XOPEN_IOV_MAX : count;
+ else
+ writev_max = (uint32_t) sc_iovmax;
+
while(count) {
r = writev(fd, iov, (int)(count > writev_max ? writev_max : count));
if(r == -1)
Reply to: