{"thread":{"id":"33452","subject":"write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","startedAt":"2013-04-09T22:31:31Z","lastAt":"2013-11-20T13:03:20Z","messageCount":12,"participants":["Filipe Cabecinhas","Junio C Hamano","Erik Faye-Lund","Torsten Bögershausen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"213732","messageId":"CAEDE852zw9EhmnVaWb_oa_BX_d_--TZoTcs1kgkMPHooM_E6Cw@mail.gmail.com","threadId":"33452","inReplyTo":null,"subject":"write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","fromName":"Filipe Cabecinhas","fromEmail":"filcab@gmail.com","sentAt":"2013-04-09T22:31:31Z","receivedAt":"2013-04-09T22:31:31Z","isPatch":false,"sender":{"key":"filcab@gmail.com","avatar":"https://gravatar.com/avatar/ff795754240a8f18498a8da02074644ff5f1969ed999b4335171d98fdb83e20f?d=mp&s=160"},"body":"Hi all,\n\n\nWhile “git svn fetch”ing a subversion repository (private, sorry),\nI've encoutered a bug that appears in several git versions (always\nwith the same symptoms):\n\ngit from master (from 2013-04-08)\ngit version 1.8.2.1 (compiled from homebrew)\ngit version 1.7.12.4 (Apple Git-37)\n\nThe only symptom is git blowing up with the error:\nfatal: write error: Invalid argument\n\nProblems showed up when this happened (in the SVN repo):\nrev A: File F with 110K is replaced with a 9G file (don't ask…)\nintermediate revs: files got added and changed, not touching file F\nrev B: File F finally got reverted to the state before rev A\n\nI can git svn fetch up to rev B-1, but svn fetching rev B will throw\nthe previously mentioned error.\n\nI traced it down to write() returning <0 and setting errno to EINVAL\nif nbytes > INT_MAX:\nhttp://fxr.watson.org/fxr/source/bsd/kern/sys_generic.c?v=xnu-2050.18.24#L573\n(the write() will eventually call dofilewrite, which has that check).\n\nTesting with dd bs=INT_MAX+1 count=1 also gets me an “Invalid\nargument” error, while bs=INT_MAX will do what's expected.\n\nI have a preliminary patch that fixes it, but it may not be the\npreferred way. The code is not ifdef'ed out and I'm doing the fix in\nwrite_in_full(), while it may be preferred to do the fix in xwrite().\n\nA radar bug has been submitted to Apple about this, but I think git\ncould tolerate the bug while it isn't fixed, by working around it.\n\nThank you,\n\n  Filipe\n\n\ndiff --git a/wrapper.c b/wrapper.c\nindex bac59d2..474d760 100644\n--- a/wrapper.c\n+++ b/wrapper.c\n@@ -187,7 +187,12 @@ ssize_t write_in_full(int fd, const void *buf, size_t count)\n \tssize_t total = 0;\n \n \twhile (count > 0) {\n-\t\tssize_t written = xwrite(fd, p, count);\n+\t\tssize_t written = 0;\n+        if (count >= INT_MAX)\n+\t\t\twritten = xwrite(fd, p, INT_MAX-1);\n+        else\n+\t\t\twritten = xwrite(fd, p, count);\n+\n \t\tif (written < 0)\n \t\t\treturn -1;\n \t\tif (!written) {\n"},{"id":"213734","messageId":"7v4nffpbct.fsf@alter.siamese.dyndns.org","threadId":"33452","inReplyTo":"CAEDE852zw9EhmnVaWb_oa_BX_d_--TZoTcs1kgkMPHooM_E6Cw@mail.gmail.com","subject":"Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-04-09T22:50:42Z","receivedAt":"2013-04-09T22:50:42Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Filipe Cabecinhas <filcab@gmail.com> writes:\n\n>\n> Testing with dd bs=INT_MAX+1 count=1 also gets me an “Invalid\n> argument” error, while bs=INT_MAX will do what's expected.\n>\n> I have a preliminary patch that fixes it, but it may not be the\n> preferred way. The code is not ifdef'ed out and I'm doing the fix in\n> write_in_full(), while it may be preferred to do the fix in xwrite().\n>\n> A radar bug has been submitted to Apple about this, but I think git\n> could tolerate the bug while it isn't fixed, by working around it.\n>\n> Thank you,\n>\n>   Filipe\n>\n> diff --git a/wrapper.c b/wrapper.c\n> index bac59d2..474d760 100644\n> --- a/wrapper.c\n> +++ b/wrapper.c\n> @@ -187,7 +187,12 @@ ssize_t write_in_full(int fd, const void *buf, size_t count)\n>  \tssize_t total = 0;\n>  \n>  \twhile (count > 0) {\n> -\t\tssize_t written = xwrite(fd, p, count);\n> +\t\tssize_t written = 0;\n> +        if (count >= INT_MAX)\n> +\t\t\twritten = xwrite(fd, p, INT_MAX-1);\n> +        else\n> +\t\t\twritten = xwrite(fd, p, count);\n\nI think it is better to fix it in much lower level of the stack, as\nother codepaths would call write(2), either thru xwrite() or\ndirectly.\n\nIdeally the fix should go to the lowest level, i.e. the write(2).  I\ndo not care if it is done in the kernel or in the libc wrapping\ncode; the above does not belong to our code (in an ideal world, that\nis).\n\nOtherwise you would have to patch everything in /usr/bin, no?\n\nBut you do not live in an ideal world and neither do we.  I think\nthe least ugly way may be to add compat/clipped-write.c that\nimplements a loop like the above in a helper function:\n\n\tssize_t clipped_write(int, const void *, size_t);\n\nand have a\n\n\t#ifdef NEED_CLIPPED_WRITE\n\t#define write(x,y,z) clipped_write((x),(y),(z))\n        #endif\n\nin git-compat-util.h, or something.  Makefile needs to get adjusted\nto link with compat/clipped-write.o when NEED_CLIPPED_WRITE is\ndefined as well.\n"},{"id":"216829","messageId":"CAEDE8504Pa_hRcHBLt4S9CL74noqrX3fWGCSf+x45zCr_43+5A@mail.gmail.com","threadId":"33452","inReplyTo":"7v4nffpbct.fsf@alter.siamese.dyndns.org","subject":"Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","fromName":"Filipe Cabecinhas","fromEmail":"filcab@gmail.com","sentAt":"2013-05-09T22:58:25Z","receivedAt":"2013-05-09T22:58:25Z","isPatch":false,"sender":{"key":"filcab@gmail.com","avatar":"https://gravatar.com/avatar/ff795754240a8f18498a8da02074644ff5f1969ed999b4335171d98fdb83e20f?d=mp&s=160"},"body":"Hi Junio,\n\nSorry for the delay. I've updated the patch to work as you suggested (I think).\nIt's attached.\n\nThank you,\n\n  Filipe\n  F\n\n\nOn Tue, Apr 9, 2013 at 3:50 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Filipe Cabecinhas <filcab@gmail.com> writes:\n>\n>>\n>> Testing with dd bs=INT_MAX+1 count=1 also gets me an “Invalid\n>> argument” error, while bs=INT_MAX will do what's expected.\n>>\n>> I have a preliminary patch that fixes it, but it may not be the\n>> preferred way. The code is not ifdef'ed out and I'm doing the fix in\n>> write_in_full(), while it may be preferred to do the fix in xwrite().\n>>\n>> A radar bug has been submitted to Apple about this, but I think git\n>> could tolerate the bug while it isn't fixed, by working around it.\n>>\n>> Thank you,\n>>\n>>   Filipe\n>>\n>> diff --git a/wrapper.c b/wrapper.c\n>> index bac59d2..474d760 100644\n>> --- a/wrapper.c\n>> +++ b/wrapper.c\n>> @@ -187,7 +187,12 @@ ssize_t write_in_full(int fd, const void *buf, size_t count)\n>>       ssize_t total = 0;\n>>\n>>       while (count > 0) {\n>> -             ssize_t written = xwrite(fd, p, count);\n>> +             ssize_t written = 0;\n>> +        if (count >= INT_MAX)\n>> +                     written = xwrite(fd, p, INT_MAX-1);\n>> +        else\n>> +                     written = xwrite(fd, p, count);\n>\n> I think it is better to fix it in much lower level of the stack, as\n> other codepaths would call write(2), either thru xwrite() or\n> directly.\n>\n> Ideally the fix should go to the lowest level, i.e. the write(2).  I\n> do not care if it is done in the kernel or in the libc wrapping\n> code; the above does not belong to our code (in an ideal world, that\n> is).\n>\n> Otherwise you would have to patch everything in /usr/bin, no?\n>\n> But you do not live in an ideal world and neither do we.  I think\n> the least ugly way may be to add compat/clipped-write.c that\n> implements a loop like the above in a helper function:\n>\n>         ssize_t clipped_write(int, const void *, size_t);\n>\n> and have a\n>\n>         #ifdef NEED_CLIPPED_WRITE\n>         #define write(x,y,z) clipped_write((x),(y),(z))\n>         #endif\n>\n> in git-compat-util.h, or something.  Makefile needs to get adjusted\n> to link with compat/clipped-write.o when NEED_CLIPPED_WRITE is\n> defined as well.\n\n\ndiff --git a/Makefile b/Makefile\nindex 0f931a2..e6aff85 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1466,6 +1466,11 @@ ifndef NO_MSGFMT_EXTENDED_OPTIONS\n \tMSGFMT += --check --statistics\n endif\n \n+ifdef NEEDS_CLIPPED_WRITE\n+\tBASIC_CFLAGS += -DNEEDS_CLIPPED_WRITE\n+\tCOMPAT_OBJS += compat/write.o\n+endif\n+\n ifneq (,$(XDL_FAST_HASH))\n \tBASIC_CFLAGS += -DXDL_FAST_HASH\n endif\ndiff --git a/compat/write.c b/compat/write.c\nnew file mode 100644\nindex 0000000..1e890aa\n--- /dev/null\n+++ b/compat/write.c\n@@ -0,0 +1,11 @@\n+#include <limits.h>\n+#include <unistd.h>\n+\n+/* Version of write that will write at most INT_MAX bytes.\n+ * Workaround a xnu bug on Mac OS X */\n+ssize_t clipped_write(int fildes, const void *buf, size_t nbyte) {\n+  if (nbyte > INT_MAX)\n+    return write(fildes, buf, INT_MAX);\n+  else\n+    return write(fildes, buf, nbyte);\n+}\ndiff --git a/config.mak.uname b/config.mak.uname\nindex d78fd3d..174703b 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -95,6 +95,7 @@ ifeq ($(uname_S),Darwin)\n \tNO_MEMMEM = YesPlease\n \tUSE_ST_TIMESPEC = YesPlease\n \tHAVE_DEV_TTY = YesPlease\n+\tNEEDS_CLIPPED_WRITE = YesPlease\n \tCOMPAT_OBJS += compat/precompose_utf8.o\n \tBASIC_CFLAGS += -DPRECOMPOSE_UNICODE\n endif\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex e955bb5..a96db23 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -185,6 +185,11 @@ int get_st_mode_bits(const char *path, int *mode);\n #define probe_utf8_pathname_composition(a,b)\n #endif\n \n+#ifdef NEEDS_CLIPPED_WRITE\n+ssize_t clipped_write(int fildes, const void *buf, size_t nbyte);\n+#define write(x, y, z) clipped_write((x), (y), (z))\n+#endif\n+\n #ifdef MKDIR_WO_TRAILING_SLASH\n #define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))\n extern int compat_mkdir_wo_trailing_slash(const char*, mode_t);\n"},{"id":"216845","messageId":"7vbo8j600q.fsf@alter.siamese.dyndns.org","threadId":"33452","inReplyTo":"CAEDE8504Pa_hRcHBLt4S9CL74noqrX3fWGCSf+x45zCr_43+5A@mail.gmail.com","subject":"Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-05-10T02:28:53Z","receivedAt":"2013-05-10T02:28:53Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Filipe Cabecinhas <filcab@gmail.com> writes:\n\n> Sorry for the delay. I've updated the patch to work as you suggested (I think).\n> It's attached.\n\nA few comments.\n\nFirst, the formalities.  Please see Documentation/SubmittingPatches,\nnotably:\n\n   - Please do not send a patch as an attachment.\n\n   - The attached patch does not seem to have any proposed commit\n     log message. For this particular change, I expect it would not\n     be more than a paragraph of several lines. Please have one.\n\n   - Please sign-off your patch.\n\nLook at patches from other high-value contributors to learn the\nstyle and the tone of log message.  For instance,\n\n    http://article.gmane.org/gmane.comp.version-control.git/223406\n\nis a good example (taken at random).\n\n> diff --git a/compat/write.c b/compat/write.c\n> new file mode 100644\n> index 0000000..1e890aa\n> --- /dev/null\n> +++ b/compat/write.c\n> @@ -0,0 +1,11 @@\n> +#include <limits.h>\n> +#include <unistd.h>\n> +\n> +/* Version of write that will write at most INT_MAX bytes.\n> + * Workaround a xnu bug on Mac OS X */\n\n\t/*\n         * We format our multi-line comments like this.\n         *\n         * Nothing other than slash-asterisk/asterisk-slash\n         * on the first and the last line of the comment block.\n         */\n\n> +ssize_t clipped_write(int fildes, const void *buf, size_t nbyte) {\n> +  if (nbyte > INT_MAX)\n> +    return write(fildes, buf, INT_MAX);\n> +  else\n> +    return write(fildes, buf, nbyte);\n> +}\n\nStyle:\n\n - opening and closing parentheses of the function body sit on\n   lines on their own.\n\n - one level of indent is 8 places, using a tab.\n\nPerhaps it would look more like this (my MUA may clobber the tabs,\nthough, before it gets to you):\n\n\tssize_t clipped_write(int fildes, const void *buf, size_t nbyte)\n\t{\n\t\tif (nbyte > INT_MAX)\n\t\t\tnbyte = INT_MAX;\n\t\treturn write(fildes, buf, nbyte);\n\t}\n\nI do not want to see this ffile called \"write.c\"; we will encounter\na platform whose write(2) behaves a way that we do not expect but is\ndifferent from this \"clipped to INT_MAX\" in the future.  The way we\nwill deal with such a platform is to add a workaround similar to\nthis patch somewhere in the compat/ directory, but if you squat on\n\"compat/write.c\", it would be a problem for that platform, as it\ncannot call its version \"compat/write.c\".\n\nPerhaps call it \"compat/clipped-write.c\" or something.\n\nBy the way, does your underlying write(2) correctly write INT_MAX\nbytes, or did you mean to clip at (INT_MAX-1)? Just double-checking.\n\nOther than that, the patch looks sensible to me.\n\nThanks.\n"},{"id":"216950","messageId":"CAEDE8507jPW4sKW7-xX5-+3YpFgfzkXzeskCNRrD7T6ynxgdNA@mail.gmail.com","threadId":"33452","inReplyTo":"7vbo8j600q.fsf@alter.siamese.dyndns.org","subject":"Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","fromName":"Filipe Cabecinhas","fromEmail":"filcab@gmail.com","sentAt":"2013-05-10T22:24:57Z","receivedAt":"2013-05-10T22:24:57Z","isPatch":false,"sender":{"key":"filcab@gmail.com","avatar":"https://gravatar.com/avatar/ff795754240a8f18498a8da02074644ff5f1969ed999b4335171d98fdb83e20f?d=mp&s=160"},"body":"Due to a bug in the Darwin kernel, write() calls have a maximum size of\nINT_MAX bytes.\n\nThis patch introduces a new compat function: clipped_write\nThis function behaves the same as write() but will write, at most, INT_MAX\ncharacters.\nIt may be necessary to include this function on Windows, too.\n\nSigned-off-by: Filipe Cabecinhas <filcab+git@gmail.com>\n---\n Makefile               |  5 +++++\n compat/clipped-write.c | 13 +++++++++++++\n config.mak.uname       |  1 +\n git-compat-util.h      |  5 +++++\n 4 files changed, 24 insertions(+)\n create mode 100644 compat/clipped-write.c\n\ndiff --git a/Makefile b/Makefile\nindex 0f931a2..ccb8f3f 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1466,6 +1466,11 @@ ifndef NO_MSGFMT_EXTENDED_OPTIONS\n  MSGFMT += --check --statistics\n endif\n\n+ifdef NEEDS_CLIPPED_WRITE\n+ BASIC_CFLAGS += -DNEEDS_CLIPPED_WRITE\n+ COMPAT_OBJS += compat/clipped-write.o\n+endif\n+\n ifneq (,$(XDL_FAST_HASH))\n  BASIC_CFLAGS += -DXDL_FAST_HASH\n endif\ndiff --git a/compat/clipped-write.c b/compat/clipped-write.c\nnew file mode 100644\nindex 0000000..9183698\n--- /dev/null\n+++ b/compat/clipped-write.c\n@@ -0,0 +1,13 @@\n+#include <limits.h>\n+#include <unistd.h>\n+\n+/*\n+ * Version of write that will write at most INT_MAX bytes.\n+ * Workaround a xnu bug on Mac OS X\n+ */\n+ssize_t clipped_write(int fildes, const void *buf, size_t nbyte)\n+{\n+ if (nbyte > INT_MAX)\n+ nbyte = INT_MAX;\n+ return write(fildes, buf, nbyte);\n+}\ndiff --git a/config.mak.uname b/config.mak.uname\nindex d78fd3d..174703b 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -95,6 +95,7 @@ ifeq ($(uname_S),Darwin)\n  NO_MEMMEM = YesPlease\n  USE_ST_TIMESPEC = YesPlease\n  HAVE_DEV_TTY = YesPlease\n+ NEEDS_CLIPPED_WRITE = YesPlease\n  COMPAT_OBJS += compat/precompose_utf8.o\n  BASIC_CFLAGS += -DPRECOMPOSE_UNICODE\n endif\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex e955bb5..a96db23 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -185,6 +185,11 @@ int get_st_mode_bits(const char *path, int *mode);\n #define probe_utf8_pathname_composition(a,b)\n #endif\n\n+#ifdef NEEDS_CLIPPED_WRITE\n+ssize_t clipped_write(int fildes, const void *buf, size_t nbyte);\n+#define write(x, y, z) clipped_write((x), (y), (z))\n+#endif\n+\n #ifdef MKDIR_WO_TRAILING_SLASH\n #define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))\n extern int compat_mkdir_wo_trailing_slash(const char*, mode_t);\n--\n1.8.2.1.343.g13c32df\n"},{"id":"216951","messageId":"7va9o2zba9.fsf@alter.siamese.dyndns.org","threadId":"33452","inReplyTo":"CAEDE8507jPW4sKW7-xX5-+3YpFgfzkXzeskCNRrD7T6ynxgdNA@mail.gmail.com","subject":"Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-05-10T23:05:02Z","receivedAt":"2013-05-10T23:05:02Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Filipe Cabecinhas <filcab@gmail.com> writes:\n\n> Due to a bug in the Darwin kernel, write() calls have a maximum size of\n> INT_MAX bytes.\n>\n> This patch introduces a new compat function: clipped_write\n> This function behaves the same as write() but will write, at most, INT_MAX\n> characters.\n> It may be necessary to include this function on Windows, too.\n>\n> Signed-off-by: Filipe Cabecinhas <filcab+git@gmail.com>\n> ---\n\nSomehow your MUA seems to have lost _all_ tabs, not just in the new\nlines in your patch but also in the existing context lines.\n\n> diff --git a/Makefile b/Makefile\n> index 0f931a2..ccb8f3f 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -1466,6 +1466,11 @@ ifndef NO_MSGFMT_EXTENDED_OPTIONS\n>   MSGFMT += --check --statistics\n>  endif\n>\n> +ifdef NEEDS_CLIPPED_WRITE\n> + BASIC_CFLAGS += -DNEEDS_CLIPPED_WRITE\n> + COMPAT_OBJS += compat/clipped-write.o\n> +endif\n> +\n> ...\n\nHere is what I resurrected and queued. I _think_ I did not make any\nsilly mistake while transcribing from your whitespace-mangled patch,\nbut please double check; I do not have any Darwin, so this hasn't\neven been compile tested.\n\nAlso I have a small suggestion I'd like you to try on top of it,\nwhich I'll be sending in a separate message.\n\nThanks.\n\n-- >8 --\nFrom: Filipe Cabecinhas <filcab@gmail.com>\nDate: Fri, 10 May 2013 15:24:57 -0700\nSubject: [PATCH] compate/clipped-write.c: large write(2) fails on Mac OS X/XNU\n\nDue to a bug in the Darwin kernel, write(2) calls have a maximum size\nof INT_MAX bytes.\n\nIntroduce a new compat function, clipped_write(), that only writes\nat most INT_MAX bytes and returns the number of bytes written, as\na substitute for write(2), and allow platforms that need this to\nenable it from the build mechanism with NEEDS_CLIPPED_WRITE.\n\nSet it for Mac OS X by default.  It may be necessary to include this\nfunction on Windows, too.\n\nSigned-off-by: Filipe Cabecinhas <filcab+git@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Makefile               |  5 +++++\n compat/clipped-write.c | 13 +++++++++++++\n config.mak.uname       |  1 +\n git-compat-util.h      |  5 +++++\n 4 files changed, 24 insertions(+)\n create mode 100644 compat/clipped-write.c\n\ndiff --git a/Makefile b/Makefile\nindex 26d3332..7076b15 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1463,6 +1463,11 @@ ifndef NO_MSGFMT_EXTENDED_OPTIONS\n \tMSGFMT += --check --statistics\n endif\n \n+ifdef NEEDS_CLIPPED_WRITE\n+\tBASIC_CFLAGS += -DNEEDS_CLIPPED_WRITE\n+\tCOMPAT_OBJS += compat/clipped-write.o\n+endif\n+\n ifneq (,$(XDL_FAST_HASH))\n \tBASIC_CFLAGS += -DXDL_FAST_HASH\n endif\ndiff --git a/compat/clipped-write.c b/compat/clipped-write.c\nnew file mode 100644\nindex 0000000..9183698\n--- /dev/null\n+++ b/compat/clipped-write.c\n@@ -0,0 +1,13 @@\n+#include <limits.h>\n+#include <unistd.h>\n+\n+/*\n+ * Version of write that will write at most INT_MAX bytes.\n+ * Workaround a xnu bug on Mac OS X\n+ */\n+ssize_t clipped_write(int fildes, const void *buf, size_t nbyte)\n+{\n+\tif (nbyte > INT_MAX)\n+\t\tnbyte = INT_MAX;\n+\treturn write(fildes, buf, nbyte);\n+}\ndiff --git a/config.mak.uname b/config.mak.uname\nindex e09af8f..e689a9a 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -95,6 +95,7 @@ ifeq ($(uname_S),Darwin)\n \tNO_MEMMEM = YesPlease\n \tUSE_ST_TIMESPEC = YesPlease\n \tHAVE_DEV_TTY = YesPlease\n+\tNEEDS_CLIPPED_WRITE = YesPlease\n \tCOMPAT_OBJS += compat/precompose_utf8.o\n \tBASIC_CFLAGS += -DPRECOMPOSE_UNICODE\n endif\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex b636e0d..3144b8d 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -181,6 +181,11 @@ typedef unsigned long uintptr_t;\n #define probe_utf8_pathname_composition(a,b)\n #endif\n \n+#ifdef NEEDS_CLIPPED_WRITE\n+ssize_t clipped_write(int fildes, const void *buf, size_t nbyte);\n+#define write(x,y,z) clipped_write((x),(y),(z))\n+#endif\n+\n #ifdef MKDIR_WO_TRAILING_SLASH\n #define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))\n extern int compat_mkdir_wo_trailing_slash(const char*, mode_t);\n-- \n1.8.3-rc1-268-g30389da\n"},{"id":"216952","messageId":"7v38tuzb0m.fsf@alter.siamese.dyndns.org","threadId":"33452","inReplyTo":"7va9o2zba9.fsf@alter.siamese.dyndns.org","subject":"Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-05-10T23:10:49Z","receivedAt":"2013-05-10T23:10:49Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Also I have a small suggestion I'd like you to try on top of it,\n> which I'll be sending in a separate message.\n\nThe first hunk is to match other Makefile knobs the builders can\ntweak with minimum documentation.\n\nAs you hinted that there may be other platforms that may want to use\nthe clipped-write, I would prefer to see this file _not_ directly\ninclude any system headers, but let git-compat-util.h to absorb\nplatform differences instead.\n\nOf course, inside this file, we do need to use the underlying\nwrite(2), so immediately after including the header, we #undef write\nso that this compilation unit will make a call to the platform\nimplementation of the function.\n\nI do not expect the follow-up patch to Makefile to cause any\nproblem, but I'd like to see the change to compat/clipped-write.c\ndouble checked on a real Mac OS X system, so that we can squash this\npatch into your original.\n\nThanks.\n\n Makefile               | 3 +++\n compat/clipped-write.c | 4 ++--\n 2 files changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 7076b15..0434715 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -69,6 +69,9 @@ all::\n # Define NO_MSGFMT_EXTENDED_OPTIONS if your implementation of msgfmt\n # doesn't support GNU extensions like --check and --statistics\n #\n+# Define NEEDS_CLIPPED_WRITE if your write(2) cannot write more than\n+# INT_MAX bytes at once (e.g. MacOS X).\n+#\n # Define HAVE_PATHS_H if you have paths.h and want to use the default PATH\n # it specifies.\n #\ndiff --git a/compat/clipped-write.c b/compat/clipped-write.c\nindex 9183698..b8f98ff 100644\n--- a/compat/clipped-write.c\n+++ b/compat/clipped-write.c\n@@ -1,5 +1,5 @@\n-#include <limits.h>\n-#include <unistd.h>\n+#include \"../git-compat-util.h\"\n+#undef write\n \n /*\n  * Version of write that will write at most INT_MAX bytes.\n"},{"id":"216953","messageId":"CAEDE851rRw24Dpxugt3_qJBtROdfcv4c6kskaizXnVy=gYVCBg@mail.gmail.com","threadId":"33452","inReplyTo":"7va9o2zba9.fsf@alter.siamese.dyndns.org","subject":"Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","fromName":"Filipe Cabecinhas","fromEmail":"filcab@gmail.com","sentAt":"2013-05-10T23:13:31Z","receivedAt":"2013-05-10T23:13:31Z","isPatch":false,"sender":{"key":"filcab@gmail.com","avatar":"https://gravatar.com/avatar/ff795754240a8f18498a8da02074644ff5f1969ed999b4335171d98fdb83e20f?d=mp&s=160"},"body":"Hi Junio,\n\nThanks for helping. Your text is correct and only diffs from my patch\nin the #define write(...) part, where I suppose you stripped the\nspaced in the arglist.\n\nThank you,\n\n  Filipe\n\n  F\n\n\nOn Fri, May 10, 2013 at 4:05 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Filipe Cabecinhas <filcab@gmail.com> writes:\n>\n>> Due to a bug in the Darwin kernel, write() calls have a maximum size of\n>> INT_MAX bytes.\n>>\n>> This patch introduces a new compat function: clipped_write\n>> This function behaves the same as write() but will write, at most, INT_MAX\n>> characters.\n>> It may be necessary to include this function on Windows, too.\n>>\n>> Signed-off-by: Filipe Cabecinhas <filcab+git@gmail.com>\n>> ---\n>\n> Somehow your MUA seems to have lost _all_ tabs, not just in the new\n> lines in your patch but also in the existing context lines.\n>\n>> diff --git a/Makefile b/Makefile\n>> index 0f931a2..ccb8f3f 100644\n>> --- a/Makefile\n>> +++ b/Makefile\n>> @@ -1466,6 +1466,11 @@ ifndef NO_MSGFMT_EXTENDED_OPTIONS\n>>   MSGFMT += --check --statistics\n>>  endif\n>>\n>> +ifdef NEEDS_CLIPPED_WRITE\n>> + BASIC_CFLAGS += -DNEEDS_CLIPPED_WRITE\n>> + COMPAT_OBJS += compat/clipped-write.o\n>> +endif\n>> +\n>> ...\n>\n> Here is what I resurrected and queued. I _think_ I did not make any\n> silly mistake while transcribing from your whitespace-mangled patch,\n> but please double check; I do not have any Darwin, so this hasn't\n> even been compile tested.\n>\n> Also I have a small suggestion I'd like you to try on top of it,\n> which I'll be sending in a separate message.\n>\n> Thanks.\n>\n> -- >8 --\n> From: Filipe Cabecinhas <filcab@gmail.com>\n> Date: Fri, 10 May 2013 15:24:57 -0700\n> Subject: [PATCH] compate/clipped-write.c: large write(2) fails on Mac OS X/XNU\n>\n> Due to a bug in the Darwin kernel, write(2) calls have a maximum size\n> of INT_MAX bytes.\n>\n> Introduce a new compat function, clipped_write(), that only writes\n> at most INT_MAX bytes and returns the number of bytes written, as\n> a substitute for write(2), and allow platforms that need this to\n> enable it from the build mechanism with NEEDS_CLIPPED_WRITE.\n>\n> Set it for Mac OS X by default.  It may be necessary to include this\n> function on Windows, too.\n>\n> Signed-off-by: Filipe Cabecinhas <filcab+git@gmail.com>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  Makefile               |  5 +++++\n>  compat/clipped-write.c | 13 +++++++++++++\n>  config.mak.uname       |  1 +\n>  git-compat-util.h      |  5 +++++\n>  4 files changed, 24 insertions(+)\n>  create mode 100644 compat/clipped-write.c\n>\n> diff --git a/Makefile b/Makefile\n> index 26d3332..7076b15 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -1463,6 +1463,11 @@ ifndef NO_MSGFMT_EXTENDED_OPTIONS\n>         MSGFMT += --check --statistics\n>  endif\n>\n> +ifdef NEEDS_CLIPPED_WRITE\n> +       BASIC_CFLAGS += -DNEEDS_CLIPPED_WRITE\n> +       COMPAT_OBJS += compat/clipped-write.o\n> +endif\n> +\n>  ifneq (,$(XDL_FAST_HASH))\n>         BASIC_CFLAGS += -DXDL_FAST_HASH\n>  endif\n> diff --git a/compat/clipped-write.c b/compat/clipped-write.c\n> new file mode 100644\n> index 0000000..9183698\n> --- /dev/null\n> +++ b/compat/clipped-write.c\n> @@ -0,0 +1,13 @@\n> +#include <limits.h>\n> +#include <unistd.h>\n> +\n> +/*\n> + * Version of write that will write at most INT_MAX bytes.\n> + * Workaround a xnu bug on Mac OS X\n> + */\n> +ssize_t clipped_write(int fildes, const void *buf, size_t nbyte)\n> +{\n> +       if (nbyte > INT_MAX)\n> +               nbyte = INT_MAX;\n> +       return write(fildes, buf, nbyte);\n> +}\n> diff --git a/config.mak.uname b/config.mak.uname\n> index e09af8f..e689a9a 100644\n> --- a/config.mak.uname\n> +++ b/config.mak.uname\n> @@ -95,6 +95,7 @@ ifeq ($(uname_S),Darwin)\n>         NO_MEMMEM = YesPlease\n>         USE_ST_TIMESPEC = YesPlease\n>         HAVE_DEV_TTY = YesPlease\n> +       NEEDS_CLIPPED_WRITE = YesPlease\n>         COMPAT_OBJS += compat/precompose_utf8.o\n>         BASIC_CFLAGS += -DPRECOMPOSE_UNICODE\n>  endif\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index b636e0d..3144b8d 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -181,6 +181,11 @@ typedef unsigned long uintptr_t;\n>  #define probe_utf8_pathname_composition(a,b)\n>  #endif\n>\n> +#ifdef NEEDS_CLIPPED_WRITE\n> +ssize_t clipped_write(int fildes, const void *buf, size_t nbyte);\n> +#define write(x,y,z) clipped_write((x),(y),(z))\n> +#endif\n> +\n>  #ifdef MKDIR_WO_TRAILING_SLASH\n>  #define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))\n>  extern int compat_mkdir_wo_trailing_slash(const char*, mode_t);\n> --\n> 1.8.3-rc1-268-g30389da\n>\n"},{"id":"216954","messageId":"CAEDE853WiuoPenuuBgPehTg89_cLfBckr3CD=fEMuXTXwVv5kQ@mail.gmail.com","threadId":"33452","inReplyTo":"CAEDE851rRw24Dpxugt3_qJBtROdfcv4c6kskaizXnVy=gYVCBg@mail.gmail.com","subject":"Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","fromName":"Filipe Cabecinhas","fromEmail":"filcab@gmail.com","sentAt":"2013-05-10T23:19:48Z","receivedAt":"2013-05-10T23:19:48Z","isPatch":false,"sender":{"key":"filcab@gmail.com","avatar":"https://gravatar.com/avatar/ff795754240a8f18498a8da02074644ff5f1969ed999b4335171d98fdb83e20f?d=mp&s=160"},"body":"Hi Junio,\n\nIt compiles cleanly and runs. I'm running the test suite anyway, but\ndon't expect any change from your latest patch.\n\nThank you,\n\n  Filipe\n  F\n\n\nOn Fri, May 10, 2013 at 4:13 PM, Filipe Cabecinhas <filcab@gmail.com> wrote:\n> Hi Junio,\n>\n> Thanks for helping. Your text is correct and only diffs from my patch\n> in the #define write(...) part, where I suppose you stripped the\n> spaced in the arglist.\n>\n> Thank you,\n>\n>   Filipe\n>\n>   F\n>\n>\n> On Fri, May 10, 2013 at 4:05 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Filipe Cabecinhas <filcab@gmail.com> writes:\n>>\n>>> Due to a bug in the Darwin kernel, write() calls have a maximum size of\n>>> INT_MAX bytes.\n>>>\n>>> This patch introduces a new compat function: clipped_write\n>>> This function behaves the same as write() but will write, at most, INT_MAX\n>>> characters.\n>>> It may be necessary to include this function on Windows, too.\n>>>\n>>> Signed-off-by: Filipe Cabecinhas <filcab+git@gmail.com>\n>>> ---\n>>\n>> Somehow your MUA seems to have lost _all_ tabs, not just in the new\n>> lines in your patch but also in the existing context lines.\n>>\n>>> diff --git a/Makefile b/Makefile\n>>> index 0f931a2..ccb8f3f 100644\n>>> --- a/Makefile\n>>> +++ b/Makefile\n>>> @@ -1466,6 +1466,11 @@ ifndef NO_MSGFMT_EXTENDED_OPTIONS\n>>>   MSGFMT += --check --statistics\n>>>  endif\n>>>\n>>> +ifdef NEEDS_CLIPPED_WRITE\n>>> + BASIC_CFLAGS += -DNEEDS_CLIPPED_WRITE\n>>> + COMPAT_OBJS += compat/clipped-write.o\n>>> +endif\n>>> +\n>>> ...\n>>\n>> Here is what I resurrected and queued. I _think_ I did not make any\n>> silly mistake while transcribing from your whitespace-mangled patch,\n>> but please double check; I do not have any Darwin, so this hasn't\n>> even been compile tested.\n>>\n>> Also I have a small suggestion I'd like you to try on top of it,\n>> which I'll be sending in a separate message.\n>>\n>> Thanks.\n>>\n>> -- >8 --\n>> From: Filipe Cabecinhas <filcab@gmail.com>\n>> Date: Fri, 10 May 2013 15:24:57 -0700\n>> Subject: [PATCH] compate/clipped-write.c: large write(2) fails on Mac OS X/XNU\n>>\n>> Due to a bug in the Darwin kernel, write(2) calls have a maximum size\n>> of INT_MAX bytes.\n>>\n>> Introduce a new compat function, clipped_write(), that only writes\n>> at most INT_MAX bytes and returns the number of bytes written, as\n>> a substitute for write(2), and allow platforms that need this to\n>> enable it from the build mechanism with NEEDS_CLIPPED_WRITE.\n>>\n>> Set it for Mac OS X by default.  It may be necessary to include this\n>> function on Windows, too.\n>>\n>> Signed-off-by: Filipe Cabecinhas <filcab+git@gmail.com>\n>> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n>> ---\n>>  Makefile               |  5 +++++\n>>  compat/clipped-write.c | 13 +++++++++++++\n>>  config.mak.uname       |  1 +\n>>  git-compat-util.h      |  5 +++++\n>>  4 files changed, 24 insertions(+)\n>>  create mode 100644 compat/clipped-write.c\n>>\n>> diff --git a/Makefile b/Makefile\n>> index 26d3332..7076b15 100644\n>> --- a/Makefile\n>> +++ b/Makefile\n>> @@ -1463,6 +1463,11 @@ ifndef NO_MSGFMT_EXTENDED_OPTIONS\n>>         MSGFMT += --check --statistics\n>>  endif\n>>\n>> +ifdef NEEDS_CLIPPED_WRITE\n>> +       BASIC_CFLAGS += -DNEEDS_CLIPPED_WRITE\n>> +       COMPAT_OBJS += compat/clipped-write.o\n>> +endif\n>> +\n>>  ifneq (,$(XDL_FAST_HASH))\n>>         BASIC_CFLAGS += -DXDL_FAST_HASH\n>>  endif\n>> diff --git a/compat/clipped-write.c b/compat/clipped-write.c\n>> new file mode 100644\n>> index 0000000..9183698\n>> --- /dev/null\n>> +++ b/compat/clipped-write.c\n>> @@ -0,0 +1,13 @@\n>> +#include <limits.h>\n>> +#include <unistd.h>\n>> +\n>> +/*\n>> + * Version of write that will write at most INT_MAX bytes.\n>> + * Workaround a xnu bug on Mac OS X\n>> + */\n>> +ssize_t clipped_write(int fildes, const void *buf, size_t nbyte)\n>> +{\n>> +       if (nbyte > INT_MAX)\n>> +               nbyte = INT_MAX;\n>> +       return write(fildes, buf, nbyte);\n>> +}\n>> diff --git a/config.mak.uname b/config.mak.uname\n>> index e09af8f..e689a9a 100644\n>> --- a/config.mak.uname\n>> +++ b/config.mak.uname\n>> @@ -95,6 +95,7 @@ ifeq ($(uname_S),Darwin)\n>>         NO_MEMMEM = YesPlease\n>>         USE_ST_TIMESPEC = YesPlease\n>>         HAVE_DEV_TTY = YesPlease\n>> +       NEEDS_CLIPPED_WRITE = YesPlease\n>>         COMPAT_OBJS += compat/precompose_utf8.o\n>>         BASIC_CFLAGS += -DPRECOMPOSE_UNICODE\n>>  endif\n>> diff --git a/git-compat-util.h b/git-compat-util.h\n>> index b636e0d..3144b8d 100644\n>> --- a/git-compat-util.h\n>> +++ b/git-compat-util.h\n>> @@ -181,6 +181,11 @@ typedef unsigned long uintptr_t;\n>>  #define probe_utf8_pathname_composition(a,b)\n>>  #endif\n>>\n>> +#ifdef NEEDS_CLIPPED_WRITE\n>> +ssize_t clipped_write(int fildes, const void *buf, size_t nbyte);\n>> +#define write(x,y,z) clipped_write((x),(y),(z))\n>> +#endif\n>> +\n>>  #ifdef MKDIR_WO_TRAILING_SLASH\n>>  #define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))\n>>  extern int compat_mkdir_wo_trailing_slash(const char*, mode_t);\n>> --\n>> 1.8.3-rc1-268-g30389da\n>>\n"},{"id":"216955","messageId":"7vy5bmxv8o.fsf@alter.siamese.dyndns.org","threadId":"33452","inReplyTo":"CAEDE853WiuoPenuuBgPehTg89_cLfBckr3CD=fEMuXTXwVv5kQ@mail.gmail.com","subject":"Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-05-10T23:36:55Z","receivedAt":"2013-05-10T23:36:55Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Filipe Cabecinhas <filcab@gmail.com> writes:\n\n> It compiles cleanly and runs. I'm running the test suite anyway, but\n> don't expect any change from your latest patch.\n\nHeh, I do not think we did write(2) of that many bytes in our test\nsuite ;-)\n\nThanks.\n"},{"id":"230833","messageId":"CABPQNSaWTMCeCCnxkRV-Cri7-iQrRknHfJvvN_2Rs9V51OS81w@mail.gmail.com","threadId":"33452","inReplyTo":"7va9o2zba9.fsf@alter.siamese.dyndns.org","subject":"Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2013-11-20T10:15:47Z","receivedAt":"2013-11-20T10:15:47Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"I know I'm extremely late to the party, and this patch has already\nlanded, but...\n\nOn Sat, May 11, 2013 at 1:05 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Filipe Cabecinhas <filcab@gmail.com> writes:\n>\n>> Due to a bug in the Darwin kernel, write() calls have a maximum size of\n>> INT_MAX bytes.\n>>\n>> This patch introduces a new compat function: clipped_write\n>> This function behaves the same as write() but will write, at most, INT_MAX\n>> characters.\n>> It may be necessary to include this function on Windows, too.\n\nWe are already doing something similar for Windows in mingw_write (see\ncompat/mingw.c), but with a much smaller size.\n\nIt feels a bit pointless to duplicate this logic.\n\n> diff --git a/compat/clipped-write.c b/compat/clipped-write.c\n> new file mode 100644\n> index 0000000..9183698\n> --- /dev/null\n> +++ b/compat/clipped-write.c\n> @@ -0,0 +1,13 @@\n> +#include <limits.h>\n> +#include <unistd.h>\n> +\n> +/*\n> + * Version of write that will write at most INT_MAX bytes.\n> + * Workaround a xnu bug on Mac OS X\n> + */\n> +ssize_t clipped_write(int fildes, const void *buf, size_t nbyte)\n> +{\n> +       if (nbyte > INT_MAX)\n> +               nbyte = INT_MAX;\n> +       return write(fildes, buf, nbyte);\n> +}\n\nIf we were to reuse this logic with Windows, we'd need to have some\nway of overriding the max-size of the write.\n"},{"id":"230843","messageId":"528CB318.1070201@web.de","threadId":"33452","inReplyTo":"CABPQNSaWTMCeCCnxkRV-Cri7-iQrRknHfJvvN_2Rs9V51OS81w@mail.gmail.com","subject":"Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2013-11-20T13:03:20Z","receivedAt":"2013-11-20T13:03:20Z","isPatch":false,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"Hej,\nI think the patch went in and out in git.git, please see below.\n\n(I coudn't the following  in msysgit,\n but if it was there, the clipped_write() for Windows could go away.\n\n/Torsten\n\n\n\ncommit 0b6806b9e45c659d25b87fb5713c920a3081eac8\nAuthor: Steffen Prohaska <prohaska@zib.de>\nDate:   Tue Aug 20 08:43:54 2013 +0200\n\n    xread, xwrite: limit size of IO to 8MB\n    \n    Checking out 2GB or more through an external filter (see test) fails\n    on Mac OS X 10.8.4 (12E55) for a 64-bit executable with:\n    \n        error: read from external filter cat failed\n        error: cannot feed the input to external filter cat\n        error: cat died of signal 13\n        error: external filter cat failed 141\n        error: external filter cat failed\n    \n    The reason is that read() immediately returns with EINVAL when asked\n    to read more than 2GB.  According to POSIX [1], if the value of\n    nbyte passed to read() is greater than SSIZE_MAX, the result is\n    implementation-defined.  The write function has the same restriction\n    [2].  Since OS X still supports running 32-bit executables, the\n    32-bit limit (SSIZE_MAX = INT_MAX = 2GB - 1) seems to be also\n    imposed on 64-bit executables under certain conditions.  For write,\n    the problem has been addressed earlier [6c642a].\n    \n    Address the problem for read() and write() differently, by limiting\n    size of IO chunks unconditionally on all platforms in xread() and\n    xwrite().  Large chunks only cause problems, like causing latencies\n    when killing the process, even if OS X was not buggy.  Doing IO in\n    reasonably sized smaller chunks should have no negative impact on\n    performance.\n    \n    The compat wrapper clipped_write() introduced earlier [6c642a] is\n    not needed anymore.  It will be reverted in a separate commit.  The\n    new test catches read and write problems.\n    \n    Note that 'git add' exits with 0 even if it prints filtering errors\n    to stderr.  The test, therefore, checks stderr.  'git add' should\n    probably be changed (sometime in another commit) to exit with\n    nonzero if filtering fails.  The test could then be changed to use\n    test_must_fail.\n\n\nOn 2013-11-20 11.15, Erik Faye-Lund wrote:\n> I know I'm extremely late to the party, and this patch has already\n> landed, but...\n> \n> On Sat, May 11, 2013 at 1:05 AM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Filipe Cabecinhas <filcab@gmail.com> writes:\n>>\n>>> Due to a bug in the Darwin kernel, write() calls have a maximum size of\n>>> INT_MAX bytes.\n>>>\n>>> This patch introduces a new compat function: clipped_write\n>>> This function behaves the same as write() but will write, at most, INT_MAX\n>>> characters.\n>>> It may be necessary to include this function on Windows, too.\n> \n> We are already doing something similar for Windows in mingw_write (see\n> compat/mingw.c), but with a much smaller size.\n> \n> It feels a bit pointless to duplicate this logic.\n> \n>> diff --git a/compat/clipped-write.c b/compat/clipped-write.c\n>> new file mode 100644\n>> index 0000000..9183698\n>> --- /dev/null\n>> +++ b/compat/clipped-write.c\n>> @@ -0,0 +1,13 @@\n>> +#include <limits.h>\n>> +#include <unistd.h>\n>> +\n>> +/*\n>> + * Version of write that will write at most INT_MAX bytes.\n>> + * Workaround a xnu bug on Mac OS X\n>> + */\n>> +ssize_t clipped_write(int fildes, const void *buf, size_t nbyte)\n>> +{\n>> +       if (nbyte > INT_MAX)\n>> +               nbyte = INT_MAX;\n>> +       return write(fildes, buf, nbyte);\n>> +}\n> \n> If we were to reuse this logic with Windows, we'd need to have some\n> way of overriding the max-size of the write.\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n> \n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/groups/opt_out.\n"}]}