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
Erik Faye-Lund <kusmabite@gmail.com>
Date
Nov 20, 2013, 10:15 UTC
Message-ID
<CABPQNSaWTMCeCCnxkRV-Cri7-iQrRknHfJvvN_2Rs9V51OS81w@mail.gmail.com>
In-Reply-To
<7va9o2zba9.fsf@alter.siamese.dyndns.org>

I know I'm extremely late to the party, and this patch has already landed, but...

On Sat, May 11, 2013 at 1:05 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 9 quoted lines
> Filipe Cabecinhas <filcab@gmail.com> writes:
>
>> Due to a bug in the Darwin kernel, write() calls have a maximum size of
>> INT_MAX bytes.
>>
>> This patch introduces a new compat function: clipped_write
>> This function behaves the same as write() but will write, at most, INT_MAX
>> characters.
>> It may be necessary to include this function on Windows, too.

We are already doing something similar for Windows in mingw_write (see compat/mingw.c), but with a much smaller size.

It feels a bit pointless to duplicate this logic.
Show 19 quoted lines
> diff --git a/compat/clipped-write.c b/compat/clipped-write.c
> new file mode 100644
> index 0000000..9183698
> --- /dev/null
> +++ b/compat/clipped-write.c
> @@ -0,0 +1,13 @@
> +#include <limits.h>
> +#include <unistd.h>
> +
> +/*
> + * Version of write that will write at most INT_MAX bytes.
> + * Workaround a xnu bug on Mac OS X
> + */
> +ssize_t clipped_write(int fildes, const void *buf, size_t nbyte)
> +{
> +       if (nbyte > INT_MAX)
> +               nbyte = INT_MAX;
> +       return write(fildes, buf, nbyte);
> +}

If we were to reuse this logic with Windows, we'd need to have some way of overriding the max-size of the write.

Previous: Junio C HamanoNext: Torsten Bögershausen
Message 11 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.