Skip to content

Commit ec4f39b

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 24b56ae commit ec4f39b

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

git-compat-util.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,28 @@ static inline unsigned long cast_size_t_to_ulong(size_t a)
995995
return (unsigned long)a;
996996
}
997997

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+
9981020
#ifdef HAVE_ALLOCA_H
9991021
# include <alloca.h>
10001022
# define xalloca(size) (alloca(size))

wrapper.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,28 +161,6 @@ void xsetenv(const char *name, const char *value, int overwrite)
161161
die_errno(_("could not setenv '%s'"), name ? name : "(null)");
162162
}
163163

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-
186164
/**
187165
* xopen() is the same as open(), but it die()s if the open() fails.
188166
*/

0 commit comments

Comments
 (0)