Skip to content

Commit 29d5350

Browse files
committed
Merge branch 'fc/macos-x-clipped-write'
Mac OS X does not like to write(2) more than INT_MAX number of bytes. * fc/macos-x-clipped-write: compate/clipped-write.c: large write(2) fails on Mac OS X/XNU
2 parents 1197c22 + 6c642a8 commit 29d5350

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ all::
6969
# Define NO_MSGFMT_EXTENDED_OPTIONS if your implementation of msgfmt
7070
# doesn't support GNU extensions like --check and --statistics
7171
#
72+
# Define NEEDS_CLIPPED_WRITE if your write(2) cannot write more than
73+
# INT_MAX bytes at once (e.g. MacOS X).
74+
#
7275
# Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
7376
# it specifies.
7477
#
@@ -1465,6 +1468,11 @@ ifndef NO_MSGFMT_EXTENDED_OPTIONS
14651468
MSGFMT += --check --statistics
14661469
endif
14671470

1471+
ifdef NEEDS_CLIPPED_WRITE
1472+
BASIC_CFLAGS += -DNEEDS_CLIPPED_WRITE
1473+
COMPAT_OBJS += compat/clipped-write.o
1474+
endif
1475+
14681476
ifneq (,$(XDL_FAST_HASH))
14691477
BASIC_CFLAGS += -DXDL_FAST_HASH
14701478
endif

compat/clipped-write.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "../git-compat-util.h"
2+
#undef write
3+
4+
/*
5+
* Version of write that will write at most INT_MAX bytes.
6+
* Workaround a xnu bug on Mac OS X
7+
*/
8+
ssize_t clipped_write(int fildes, const void *buf, size_t nbyte)
9+
{
10+
if (nbyte > INT_MAX)
11+
nbyte = INT_MAX;
12+
return write(fildes, buf, nbyte);
13+
}

config.mak.uname

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ ifeq ($(uname_S),Darwin)
9595
NO_MEMMEM = YesPlease
9696
USE_ST_TIMESPEC = YesPlease
9797
HAVE_DEV_TTY = YesPlease
98+
NEEDS_CLIPPED_WRITE = YesPlease
9899
COMPAT_OBJS += compat/precompose_utf8.o
99100
BASIC_CFLAGS += -DPRECOMPOSE_UNICODE
100101
endif

git-compat-util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ int get_st_mode_bits(const char *path, int *mode);
185185
#define probe_utf8_pathname_composition(a,b)
186186
#endif
187187

188+
#ifdef NEEDS_CLIPPED_WRITE
189+
ssize_t clipped_write(int fildes, const void *buf, size_t nbyte);
190+
#define write(x,y,z) clipped_write((x),(y),(z))
191+
#endif
192+
188193
#ifdef MKDIR_WO_TRAILING_SLASH
189194
#define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))
190195
extern int compat_mkdir_wo_trailing_slash(const char*, mode_t);

0 commit comments

Comments
 (0)