--- mlton-r6698.patched/runtime/util/safe.h 2008-09-09 10:54:08.000000000 +0200 +++ mlton-r6698/runtime/util/safe.h 2008-08-13 15:07:57.000000000 +0200 @@ -68,8 +68,21 @@ static inline void fwrite_safe (const void *buf, size_t size, size_t count, FILE *f) { size_t res; - - res = fwrite (buf, size, count, f); + enum { + WRITE_CHUNK_SIZE = 0x2000000, /* 32M */ + }; + + res = 0; + while (res < count) { + size_t n; + n = count - res; + if (n > WRITE_CHUNK_SIZE) + n = WRITE_CHUNK_SIZE; + n = fwrite ((void *) ((char *) buf + res), size, n, f); + if (n == 0) + break; + res += n; + } if (res != count) diee ("fwrite (_, %"PRIuMAX", %"PRIuMAX", _) failed " "(only wrote %"PRIuMAX").\n",