Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Therning <niklas@therning.org>2016-11-18 16:30:22 +0300
committerGitHub <noreply@github.com>2016-11-18 16:30:22 +0300
commit9add1a79714a50f0ef2ef473dc41e2e30bb1b1fa (patch)
treead9597b43fe189057b4c341a0b35dbf346263df9 /support
parente264edcf35d33ad051b67b3c20441c1638b75c9a (diff)
parent3df6f5c3f3ba949f5cb144be3d70c7ec60a70660 (diff)
Merge pull request #3985 from ntherning/fix-Mono.Posix-on-windows
Fix Mono.Posix tests on Windows
Diffstat (limited to 'support')
-rw-r--r--support/errno.c6
-rw-r--r--support/map.c40
-rw-r--r--support/map.h1
-rw-r--r--support/stdio.c16
4 files changed, 34 insertions, 29 deletions
diff --git a/support/errno.c b/support/errno.c
index 74c2fdf5648..b066d462b16 100644
--- a/support/errno.c
+++ b/support/errno.c
@@ -10,6 +10,12 @@
G_BEGIN_DECLS
+int
+Mono_Posix_Stdlib_GetLastError (void)
+{
+ return errno;
+}
+
void
Mono_Posix_Stdlib_SetLastError (int error_number)
{
diff --git a/support/map.c b/support/map.c
index 92fca755371..615584889df 100644
--- a/support/map.c
+++ b/support/map.c
@@ -4716,52 +4716,36 @@ int Mono_Posix_ToPosixMadviseAdvice (int x, int *r)
int Mono_Posix_FromSeekFlags (short x, short *r)
{
*r = 0;
- if (x == Mono_Posix_SeekFlags_L_INCR)
#ifdef L_INCR
+ if (x == Mono_Posix_SeekFlags_L_INCR)
{*r = L_INCR; return 0;}
-#else /* def L_INCR */
- {errno = EINVAL; return -1;}
-#endif /* ndef L_INCR */
- if (x == Mono_Posix_SeekFlags_L_SET)
+#endif /* def L_INCR */
#ifdef L_SET
+ if (x == Mono_Posix_SeekFlags_L_SET)
{*r = L_SET; return 0;}
-#else /* def L_SET */
- {errno = EINVAL; return -1;}
-#endif /* ndef L_SET */
- if (x == Mono_Posix_SeekFlags_L_XTND)
+#endif /* def L_SET */
#ifdef L_XTND
+ if (x == Mono_Posix_SeekFlags_L_XTND)
{*r = L_XTND; return 0;}
-#else /* def L_XTND */
- {errno = EINVAL; return -1;}
-#endif /* ndef L_XTND */
- if (x == Mono_Posix_SeekFlags_SEEK_CUR)
+#endif /* def L_XTND */
#ifdef SEEK_CUR
+ if (x == Mono_Posix_SeekFlags_SEEK_CUR)
{*r = SEEK_CUR; return 0;}
-#else /* def SEEK_CUR */
- {errno = EINVAL; return -1;}
-#endif /* ndef SEEK_CUR */
- if (x == Mono_Posix_SeekFlags_SEEK_END)
+#endif /* def SEEK_CUR */
#ifdef SEEK_END
+ if (x == Mono_Posix_SeekFlags_SEEK_END)
{*r = SEEK_END; return 0;}
-#else /* def SEEK_END */
- {errno = EINVAL; return -1;}
-#endif /* ndef SEEK_END */
- if (x == Mono_Posix_SeekFlags_SEEK_SET)
+#endif /* def SEEK_END */
#ifdef SEEK_SET
+ if (x == Mono_Posix_SeekFlags_SEEK_SET)
{*r = SEEK_SET; return 0;}
-#else /* def SEEK_SET */
- {errno = EINVAL; return -1;}
-#endif /* ndef SEEK_SET */
- if (x == 0)
- return 0;
+#endif /* def SEEK_SET */
errno = EINVAL; return -1;
}
int Mono_Posix_ToSeekFlags (short x, short *r)
{
*r = 0;
- if (x == 0)
- return 0;
#ifdef L_INCR
if (x == L_INCR)
{*r = Mono_Posix_SeekFlags_L_INCR; return 0;}
diff --git a/support/map.h b/support/map.h
index 8c6ef5000f2..cf6213c8c56 100644
--- a/support/map.h
+++ b/support/map.h
@@ -2184,6 +2184,7 @@ void* Mono_Posix_Stdlib_realloc (void* ptr, guint64 size);
void Mono_Posix_Stdlib_free (void* p);
int Mono_Posix_Stdlib_rewind (void* stream);
int Mono_Posix_Stdlib_setbuf (void* stream, void* buf);
+int Mono_Posix_Stdlib_GetLastError (void);
void Mono_Posix_Stdlib_SetLastError (int error);
int Mono_Posix_Stdlib_setvbuf (void* stream, void* buf, int mode, guint64 size);
void* Mono_Posix_Stdlib_fopen (char* path, char* mode);
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