summaryrefslogtreecommitdiff
path: root/wrapper.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-02-25 15:40:13 -0800
committerJunio C Hamano <gitster@pobox.com>2015-02-25 15:40:13 -0800
commit81a535da88617e2ae24b79a9d7413008e0ebc23b (patch)
tree8fc39e025a20383d1c67ee5bffa1bdee77bb91eb /wrapper.c
parent90eea883fd86a272a32c7d5f363445776e0680e2 (diff)
parenta983e6ac58094a3b2466ad3be13049ce213f9fc3 (diff)
downloadgit-81a535da88617e2ae24b79a9d7413008e0ebc23b.tar.gz
Merge branch 'jc/max-io-size-and-ssize-max'
Our default I/O size (8 MiB) for large files was too large for some platforms with smaller SSIZE_MAX, leading to read(2)/write(2) failures. * jc/max-io-size-and-ssize-max: xread/xwrite: clip MAX_IO_SIZE to SSIZE_MAX
Diffstat (limited to 'wrapper.c')
-rw-r--r--wrapper.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/wrapper.c b/wrapper.c
index 007ec0d8ea..d5a6cef2be 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -172,8 +172,22 @@ void *xcalloc(size_t nmemb, size_t size)
* 64-bit is buggy, returning EINVAL if len >= INT_MAX; and even in
* the absence of bugs, large chunks can result in bad latencies when
* you decide to kill the process.
+ *
+ * We pick 8 MiB as our default, but if the platform defines SSIZE_MAX
+ * that is smaller than that, clip it to SSIZE_MAX, as a call to
+ * read(2) or write(2) larger than that is allowed to fail. As the last
+ * resort, we allow a port to pass via CFLAGS e.g. "-DMAX_IO_SIZE=value"
+ * to override this, if the definition of SSIZE_MAX given by the platform
+ * is broken.
*/
-#define MAX_IO_SIZE (8*1024*1024)
+#ifndef MAX_IO_SIZE
+# define MAX_IO_SIZE_DEFAULT (8*1024*1024)
+# if defined(SSIZE_MAX) && (SSIZE_MAX < MAX_IO_SIZE_DEFAULT)
+# define MAX_IO_SIZE SSIZE_MAX
+# else
+# define MAX_IO_SIZE MAX_IO_SIZE_DEFAULT
+# endif
+#endif
/*
* xread() is the same a read(), but it automatically restarts read()