Skip to content

Commit 81a535d

Browse files
committed
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
2 parents 90eea88 + a983e6a commit 81a535d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

wrapper.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,22 @@ void *xcalloc(size_t nmemb, size_t size)
172172
* 64-bit is buggy, returning EINVAL if len >= INT_MAX; and even in
173173
* the absence of bugs, large chunks can result in bad latencies when
174174
* you decide to kill the process.
175+
*
176+
* We pick 8 MiB as our default, but if the platform defines SSIZE_MAX
177+
* that is smaller than that, clip it to SSIZE_MAX, as a call to
178+
* read(2) or write(2) larger than that is allowed to fail. As the last
179+
* resort, we allow a port to pass via CFLAGS e.g. "-DMAX_IO_SIZE=value"
180+
* to override this, if the definition of SSIZE_MAX given by the platform
181+
* is broken.
175182
*/
176-
#define MAX_IO_SIZE (8*1024*1024)
183+
#ifndef MAX_IO_SIZE
184+
# define MAX_IO_SIZE_DEFAULT (8*1024*1024)
185+
# if defined(SSIZE_MAX) && (SSIZE_MAX < MAX_IO_SIZE_DEFAULT)
186+
# define MAX_IO_SIZE SSIZE_MAX
187+
# else
188+
# define MAX_IO_SIZE MAX_IO_SIZE_DEFAULT
189+
# endif
190+
#endif
177191

178192
/*
179193
* xread() is the same a read(), but it automatically restarts read()

0 commit comments

Comments
 (0)