git-compat-util: make MAX_IO_SIZE define globally available

We define MAX_IO_SIZE within wrapper.c, but it's useful for any code that wants to do a raw write() for whatever reason (say, because they want different EAGAIN handling). Let's make it available everywhere. The alternative would be adding xwrite_foo() variants to give callers more options. But there's really no reason MAX_IO_SIZE needs to be abstracted away, so this give callers the most flexibility. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 17, 2022 at 02:06 UTC ec4f39b2333db94096ec2d6b900eabaf4d1e3f1b
2 files changed +22 -22
git-compat-util.h
+22
@@ -995,6 +995,28 @@ static inline unsigned long cast_size_t_to_ulong(size_t a)
995 return (unsigned long)a;
996 }
997
998 +/*
999 + * Limit size of IO chunks, because huge chunks only cause pain. OS X
1000 + * 64-bit is buggy, returning EINVAL if len >= INT_MAX; and even in
1001 + * the absence of bugs, large chunks can result in bad latencies when
1002 + * you decide to kill the process.
1003 + *
1004 + * We pick 8 MiB as our default, but if the platform defines SSIZE_MAX
1005 + * that is smaller than that, clip it to SSIZE_MAX, as a call to
1006 + * read(2) or write(2) larger than that is allowed to fail. As the last
1007 + * resort, we allow a port to pass via CFLAGS e.g. "-DMAX_IO_SIZE=value"
1008 + * to override this, if the definition of SSIZE_MAX given by the platform
1009 + * is broken.
1010 + */
1011 +#ifndef MAX_IO_SIZE
1012 +# define MAX_IO_SIZE_DEFAULT (8*1024*1024)
1013 +# if defined(SSIZE_MAX) && (SSIZE_MAX < MAX_IO_SIZE_DEFAULT)
1014 +# define MAX_IO_SIZE SSIZE_MAX
1015 +# else
1016 +# define MAX_IO_SIZE MAX_IO_SIZE_DEFAULT
1017 +# endif
1018 +#endif
1019 +
1020 #ifdef HAVE_ALLOCA_H
1021 # include <alloca.h>
1022 # define xalloca(size) (alloca(size))
wrapper.c
-22
@@ -161,28 +161,6 @@ void xsetenv(const char *name, const char *value, int overwrite)
161 die_errno(_("could not setenv '%s'"), name ? name : "(null)");
162 }
163
164 -/*
165 - * Limit size of IO chunks, because huge chunks only cause pain. OS X
166 - * 64-bit is buggy, returning EINVAL if len >= INT_MAX; and even in
167 - * the absence of bugs, large chunks can result in bad latencies when
168 - * you decide to kill the process.
169 - *
170 - * We pick 8 MiB as our default, but if the platform defines SSIZE_MAX
171 - * that is smaller than that, clip it to SSIZE_MAX, as a call to
172 - * read(2) or write(2) larger than that is allowed to fail. As the last
173 - * resort, we allow a port to pass via CFLAGS e.g. "-DMAX_IO_SIZE=value"
174 - * to override this, if the definition of SSIZE_MAX given by the platform
175 - * is broken.
176 - */
177 -#ifndef MAX_IO_SIZE
178 -# define MAX_IO_SIZE_DEFAULT (8*1024*1024)
179 -# if defined(SSIZE_MAX) && (SSIZE_MAX < MAX_IO_SIZE_DEFAULT)
180 -# define MAX_IO_SIZE SSIZE_MAX
181 -# else
182 -# define MAX_IO_SIZE MAX_IO_SIZE_DEFAULT
183 -# endif
184 -#endif
185 -
164 /**
165 * xopen() is the same as open(), but it die()s if the open() fails.
166 */