Fixes the Mono.Posix API breakage introduced in #3985
authorNiklas Therning <niklas@therning.org>
Tue, 31 Jan 2017 10:03:15 +0000 (05:03 -0500)
committerNiklas Therning <niklas@therning.org>
Wed, 1 Feb 2017 08:19:35 +0000 (09:19 +0100)
Also reverts the changes done to support/map.c. This is a generated file which
shouldn't be changed directly. An alternate fix for the problem in map.c on
Windows was to make sure L_SET et al are defined in mph.h which was already
done for Solaris.

mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs
msvc/monoposixhelper.def
msvc/monoposixhelper.vcxproj
msvc/monoposixhelper.vcxproj.filters
support/fcntl.c
support/map.c
support/mph.h
support/stdio.c
support/sys-stat.c

index 76206e3d49fd79df356948f9ba89ff85e01555f9..4ae330d5b46f74420f5ed35603c04f4f6cae15fc 100644 (file)
@@ -3085,7 +3085,7 @@ namespace Mono.Unix.Native {
                                EntryPoint="Mono_Posix_Syscall_get_at_fdcwd")]
                private static extern int get_at_fdcwd ();
 
-               public static int AT_FDCWD { get { return get_at_fdcwd (); } }
+               public static readonly int AT_FDCWD = get_at_fdcwd ();
 
                #endregion
 
@@ -3657,12 +3657,12 @@ namespace Mono.Unix.Native {
                [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
                private static extern int _L_ctermid ();
 
-               public static int L_ctermid { get { return _L_ctermid (); } }
+               public static readonly int L_ctermid = _L_ctermid ();
 
                [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
                private static extern int _L_cuserid ();
 
-               public static int L_cuserid { get { return _L_cuserid (); } }
+               public static readonly int L_cuserid = _L_cuserid ();
 
                internal static object getlogin_lock = new object ();
 
@@ -4044,9 +4044,9 @@ namespace Mono.Unix.Native {
                                EntryPoint="Mono_Posix_Syscall_get_utime_omit")]
                private static extern long get_utime_omit ();
 
-               public static long UTIME_NOW { get { return get_utime_now (); } }
+               public static readonly long UTIME_NOW = get_utime_now ();
 
-               public static long UTIME_OMIT { get { return get_utime_omit (); } }
+               public static readonly long UTIME_OMIT = get_utime_omit ();
 
                [DllImport (MPH, SetLastError=true, 
                                EntryPoint="Mono_Posix_Syscall_futimens")]
index b8cf7cbfe551818251d48c6737bc66a60f4478bc..884a248e7d402d6f8b0a850364ac0a398f211028 100644 (file)
@@ -80,6 +80,11 @@ Mono_Posix_Stdlib_stdout
 Mono_Posix_Stdlib_strlen\r
 Mono_Posix_Stdlib_tmpfile\r
 Mono_Posix_Stdlib_ungetc\r
+Mono_Posix_Syscall_L_ctermid\r
+Mono_Posix_Syscall_L_cuserid\r
+Mono_Posix_Syscall_get_at_fdcwd\r
+Mono_Posix_Syscall_get_utime_now\r
+Mono_Posix_Syscall_get_utime_omit\r
 Mono_Posix_ToAccessModes\r
 Mono_Posix_ToConfstrName\r
 Mono_Posix_ToDirectoryNotifyFlags\r
index de0276892fa51410ace9318b026d559401d2cdc4..8ea0b2ddbb4e44ac7e0513920b9921606f4aa7be 100644 (file)
     <ClCompile Include="..\support\crc32.c" />\r
     <ClCompile Include="..\support\deflate.c" />\r
     <ClCompile Include="..\support\errno.c" />\r
+    <ClCompile Include="..\support\fcntl.c" />\r
     <ClCompile Include="..\support\infback.c" />\r
     <ClCompile Include="..\support\inffast.c" />\r
     <ClCompile Include="..\support\inflate.c" />\r
     <ClCompile Include="..\support\stdio.c" />\r
     <ClCompile Include="..\support\stdlib.c" />\r
     <ClCompile Include="..\support\string.c" />\r
+    <ClCompile Include="..\support\sys-stat.c" />\r
     <ClCompile Include="..\support\trees.c" />\r
     <ClCompile Include="..\support\uncompr.c" />\r
     <ClCompile Include="..\support\zlib-helper.c" />\r
index 1cd4d6b86659f977351c9e9a6ab4f309af855c4f..9ca88289700e1c08316cc82c51967137fc1bd48b 100644 (file)
     <ClCompile Include="..\support\minizip\ioapi.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\support\fcntl.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\support\sys-stat.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\support\crc32.h">\r
index 85605d1bc21ddcedb5fdf3cd7a0aff2685cbd4cf..900a58f8104d724335b33e5cbdebb0490a64c79b 100644 (file)
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <fcntl.h>
 #include <errno.h>
+#ifdef HOST_WIN32
+#include <corecrt_io.h>
+#endif
 
 #include "map.h"
 #include "mph.h"
 
 G_BEGIN_DECLS
 
+#ifndef HOST_WIN32
 gint32
 Mono_Posix_Syscall_fcntl (gint32 fd, gint32 cmd)
 {
@@ -95,6 +101,7 @@ Mono_Posix_Syscall_fcntl_lock (gint32 fd, gint32 cmd, struct Mono_Posix_Flock *l
 
        return r;
 }
+#endif
 
 gint32
 Mono_Posix_Syscall_open (const char *pathname, gint32 flags)
index 615584889dfa5c4e7b8659d43b9dcc638481648c..92fca755371d09ab6336dd25c5c131d014c47d7d 100644 (file)
@@ -4716,36 +4716,52 @@ int Mono_Posix_ToPosixMadviseAdvice (int x, int *r)
 int Mono_Posix_FromSeekFlags (short x, short *r)
 {
        *r = 0;
-#ifdef L_INCR
        if (x == Mono_Posix_SeekFlags_L_INCR)
+#ifdef L_INCR
                {*r = L_INCR; return 0;}
-#endif /* def L_INCR */
-#ifdef L_SET
+#else /* def L_INCR */
+               {errno = EINVAL; return -1;}
+#endif /* ndef L_INCR */
        if (x == Mono_Posix_SeekFlags_L_SET)
+#ifdef L_SET
                {*r = L_SET; return 0;}
-#endif /* def L_SET */
-#ifdef L_XTND
+#else /* def L_SET */
+               {errno = EINVAL; return -1;}
+#endif /* ndef L_SET */
        if (x == Mono_Posix_SeekFlags_L_XTND)
+#ifdef L_XTND
                {*r = L_XTND; return 0;}
-#endif /* def L_XTND */
-#ifdef SEEK_CUR
+#else /* def L_XTND */
+               {errno = EINVAL; return -1;}
+#endif /* ndef L_XTND */
        if (x == Mono_Posix_SeekFlags_SEEK_CUR)
+#ifdef SEEK_CUR
                {*r = SEEK_CUR; return 0;}
-#endif /* def SEEK_CUR */
-#ifdef SEEK_END
+#else /* def SEEK_CUR */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SEEK_CUR */
        if (x == Mono_Posix_SeekFlags_SEEK_END)
+#ifdef SEEK_END
                {*r = SEEK_END; return 0;}
-#endif /* def SEEK_END */
-#ifdef SEEK_SET
+#else /* def SEEK_END */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SEEK_END */
        if (x == Mono_Posix_SeekFlags_SEEK_SET)
+#ifdef SEEK_SET
                {*r = SEEK_SET; return 0;}
-#endif /* def SEEK_SET */
+#else /* def SEEK_SET */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SEEK_SET */
+       if (x == 0)
+               return 0;
        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;}
index cb5d94131da010bec4af329b7495109199948641..141b675c01097f4e4e087756810cb5f5108bfa5c 100644 (file)
 #  endif
 #endif /* !defined(EOVERFLOW) */
 
-#if !defined (HOST_WIN32)
-
 /* 
- * Solaris doesn't define these BSD values, and if they're not present then
- * map.c:Mono_Posix_FromSeekFlags() breaks badly; see:
+ * Solaris/Windows don't define these BSD values, and if they're not present
+ * then map.c:Mono_Posix_FromSeekFlags() breaks badly; see:
  * http://bugzilla.gnome.org/show_bug.cgi?id=370081
  */
 
@@ -74,6 +72,8 @@
 #define L_XTND SEEK_END
 #endif /* ndef L_XTND */
 
+#if !defined (HOST_WIN32)
+
 /*
  * OS X doesn't define MAP_ANONYMOUS, but it does define MAP_ANON.
  * Alias them to fix: https://bugzilla.xamarin.com/show_bug.cgi?id=3419
index b7cc689deb51087588140936b4f99f1cd10d5bf8..590ff8cf821dca7ef57b2182caadf3b6151bc52f 100644 (file)
 
 G_BEGIN_DECLS
 
-#ifndef HOST_WIN32
 gint32
 Mono_Posix_Syscall_L_ctermid (void)
 {
+#ifndef HOST_WIN32
        return L_ctermid;
+#else
+       return -1;
+#endif
 }
 
 gint32
 Mono_Posix_Syscall_L_cuserid (void)
 {
-#if defined(__APPLE__) || defined (__OpenBSD__)
+#if defined(__APPLE__) || defined (__OpenBSD__) || defined (HOST_WIN32)
        return -1;
 #else
        return L_cuserid;
 #endif
 }
-#endif /* ndef HOST_WIN32 */
 
 mph_size_t
 Mono_Posix_Stdlib_fread (unsigned char *ptr, mph_size_t size, mph_size_t nmemb, void *stream)
index d71d555b4d1b1c6f97f121d507356c06d35808b8..075563b0cf4d87681cce80a5126290ede1b8a97f 100644 (file)
@@ -13,7 +13,9 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <fcntl.h>
 #include <errno.h>
 
@@ -42,8 +44,10 @@ Mono_Posix_FromStat (struct Mono_Posix_Stat *from, void *_to)
        to->st_gid         = from->st_gid;
        to->st_rdev        = from->st_rdev;
        to->st_size        = from->st_size;
+#ifndef HOST_WIN32
        to->st_blksize     = from->st_blksize;
        to->st_blocks      = from->st_blocks;
+#endif
        to->st_atime       = from->st_atime_;
        to->st_mtime       = from->st_mtime_;
        to->st_ctime       = from->st_ctime_;
@@ -76,8 +80,10 @@ Mono_Posix_ToStat (void *_from, struct Mono_Posix_Stat *to)
        to->st_gid        = from->st_gid;
        to->st_rdev       = from->st_rdev;
        to->st_size       = from->st_size;
+#ifndef HOST_WIN32
        to->st_blksize    = from->st_blksize;
        to->st_blocks     = from->st_blocks;
+#endif
        to->st_atime_     = from->st_atime;
        to->st_mtime_     = from->st_mtime;
        to->st_ctime_     = from->st_ctime;
@@ -126,6 +132,7 @@ Mono_Posix_Syscall_fstat (int filedes, struct Mono_Posix_Stat *buf)
        return r;
 }
 
+#ifndef HOST_WIN32
 gint32
 Mono_Posix_Syscall_lstat (const char *file_name, struct Mono_Posix_Stat *buf)
 {
@@ -141,6 +148,7 @@ Mono_Posix_Syscall_lstat (const char *file_name, struct Mono_Posix_Stat *buf)
                r = -1;
        return r;
 }
+#endif
 
 #ifdef HAVE_FSTATAT
 gint32
@@ -163,6 +171,7 @@ Mono_Posix_Syscall_fstatat (gint32 dirfd, const char *file_name, struct Mono_Pos
 }
 #endif
 
+#ifndef HOST_WIN32
 gint32
 Mono_Posix_Syscall_mknod (const char *pathname, guint32 mode, mph_dev_t dev)
 {
@@ -170,6 +179,7 @@ Mono_Posix_Syscall_mknod (const char *pathname, guint32 mode, mph_dev_t dev)
                return -1;
        return mknod (pathname, mode, dev);
 }
+#endif
 
 #ifdef HAVE_MKNODAT
 gint32
@@ -203,6 +213,7 @@ Mono_Posix_Syscall_get_utime_omit ()
 #endif
 }
 
+#if defined(HAVE_FUTIMENS) || defined(HAVE_UTIMENSAT)
 static inline struct timespec*
 copy_utimens (struct timespec* to, struct Mono_Posix_Timespec *from)
 {
@@ -216,6 +227,7 @@ copy_utimens (struct timespec* to, struct Mono_Posix_Timespec *from)
 
        return NULL;
 }
+#endif
 
 #ifdef HAVE_FUTIMENS
 gint32