X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=support%2Fstdio.c;h=b7cc689deb51087588140936b4f99f1cd10d5bf8;hb=9add1a79714a50f0ef2ef473dc41e2e30bb1b1fa;hp=c05913fbe248dc180443701fefae557f9409f50c;hpb=e264edcf35d33ad051b67b3c20441c1638b75c9a;p=mono.git diff --git a/support/stdio.c b/support/stdio.c index c05913fbe24..b7cc689deb5 100644 --- a/support/stdio.c +++ b/support/stdio.c @@ -49,7 +49,21 @@ Mono_Posix_Stdlib_fwrite (unsigned char *ptr, mph_size_t size, mph_size_t nmemb, mph_return_if_size_t_overflow (size); mph_return_if_size_t_overflow (nmemb); - return fwrite (ptr, (size_t) size, (size_t) nmemb, (FILE*) stream); + size_t ret = fwrite (ptr, (size_t) size, (size_t) nmemb, (FILE*) stream); +#ifdef HOST_WIN32 + // Workaround for a particular weirdness on Windows triggered by the + // StdioFileStreamTest.Write() test method. The test writes 15 bytes to a + // file, then rewinds the file pointer and reads the same bytes. It then + // writes 15 additional bytes to the file. This second write fails on + // Windows with 0 returned from fwrite(). Calling fseek() followed by a retry + // of fwrite() like we do here fixes the issue. + if (ret != nmemb) + { + fseek (stream, 0, SEEK_CUR); + ret = fwrite (ptr + (ret * nmemb), (size_t) size, (size_t) nmemb - ret, (FILE*) stream); + } +#endif + return ret; } #ifdef HAVE_VSNPRINTF