git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX

From
Junio C Hamano <gitster@pobox.com>
Date
May 10, 2013, 23:10 UTC
Message-ID
<7v38tuzb0m.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7va9o2zba9.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
> Also I have a small suggestion I'd like you to try on top of it,
> which I'll be sending in a separate message.

The first hunk is to match other Makefile knobs the builders can tweak with minimum documentation.

As you hinted that there may be other platforms that may want to use the clipped-write, I would prefer to see this file _not_ directly include any system headers, but let git-compat-util.h to absorb platform differences instead.

Of course, inside this file, we do need to use the underlying write(2), so immediately after including the header, we #undef write so that this compilation unit will make a call to the platform implementation of the function.

I do not expect the follow-up patch to Makefile to cause any problem, but I'd like to see the change to compat/clipped-write.c double checked on a real Mac OS X system, so that we can squash this patch into your original.

Thanks.
 Makefile               | 3 +++
 compat/clipped-write.c | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 7076b15..0434715 100644
--- a/Makefile
+++ b/Makefile
@@ -69,6 +69,9 @@ all::
 # Define NO_MSGFMT_EXTENDED_OPTIONS if your implementation of msgfmt
 # doesn't support GNU extensions like --check and --statistics
 #
+# Define NEEDS_CLIPPED_WRITE if your write(2) cannot write more than
+# INT_MAX bytes at once (e.g. MacOS X).
+#
 # Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
 # it specifies.
 #
diff --git a/compat/clipped-write.c b/compat/clipped-write.c
index 9183698..b8f98ff 100644
--- a/compat/clipped-write.c
+++ b/compat/clipped-write.c
@@ -1,5 +1,5 @@
-#include <limits.h>
-#include <unistd.h>
+#include "../git-compat-util.h"
+#undef write
 
 /*
  * Version of write that will write at most INT_MAX bytes.
Previous: Junio C HamanoNext: Filipe Cabecinhas
Message 7 of 12 in “write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX”
  1. Filipe CabecinhasApr 9, 2013
  2. Junio C HamanoApr 9, 2013
  3. Filipe CabecinhasMay 9, 2013
  4. Junio C HamanoMay 10, 2013
  5. Filipe CabecinhasMay 10, 2013
  6. Junio C HamanoMay 10, 2013
  7. Junio C HamanoMay 10, 2013
  8. Filipe CabecinhasMay 10, 2013
  9. Filipe CabecinhasMay 10, 2013
  10. Junio C HamanoMay 10, 2013
  11. Erik Faye-LundNov 20, 2013
  12. Torsten BögershausenNov 20, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.