[jit] Avoid licm for volatile variables, ssa ignores them so we can't detect whenever...
[mono.git] / mono / io-layer / posix.c
index 732529039ce58ab588e8d7d554e368074fdaf7f1..b51c1adf11e647046c035ae92671a008a40925ed 100644 (file)
@@ -6,6 +6,7 @@
  *
  * (C) 2002 Ximian, Inc.
  * Copyright (c) 2002-2009 Novell, Inc.
+ * Copyright 2011 Xamarin Inc
  */
 
 #include <config.h>
 #include <mono/io-layer/handles-private.h>
 #include <mono/io-layer/io-private.h>
 
+#if 0
+#define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
+
 static guint32
 convert_from_flags(int flags)
 {
@@ -39,9 +46,7 @@ convert_from_flags(int flags)
        } else if ((flags & O_ACCMODE) == O_RDWR) {
                fileaccess=GENERIC_READ|GENERIC_WRITE;
        } else {
-#ifdef DEBUG
-               g_message("%s: Can't figure out flags 0x%x", __func__, flags);
-#endif
+               DEBUG("%s: Can't figure out flags 0x%x", __func__, flags);
        }
 
        /* Maybe sort out create mode too */
@@ -56,11 +61,10 @@ gpointer _wapi_stdhandle_create (int fd, const gchar *name)
        gpointer handle;
        int flags;
        
-#ifdef DEBUG
-       g_message("%s: creating standard handle type %s, fd %d", __func__,
+       DEBUG("%s: creating standard handle type %s, fd %d", __func__,
                  name, fd);
-#endif
-       
+
+#if !defined(__native_client__)        
        /* Check if fd is valid */
        do {
                flags=fcntl(fd, F_GETFL);
@@ -70,19 +74,25 @@ gpointer _wapi_stdhandle_create (int fd, const gchar *name)
                /* Invalid fd.  Not really much point checking for EBADF
                 * specifically
                 */
-#ifdef DEBUG
-               g_message("%s: fcntl error on fd %d: %s", __func__, fd,
+               DEBUG("%s: fcntl error on fd %d: %s", __func__, fd,
                          strerror(errno));
-#endif
 
                SetLastError (_wapi_get_win32_file_error (errno));
                return(INVALID_HANDLE_VALUE);
        }
+       file_handle.fileaccess=convert_from_flags(flags);
+#else
+       /* 
+        * fcntl will return -1 in nacl, as there is no real file system API. 
+        * Yet, standard streams are available.
+        */
+       file_handle.fileaccess = (fd == STDIN_FILENO) ? GENERIC_READ : GENERIC_WRITE;
+#endif
 
+       file_handle.fd = fd;
        file_handle.filename = g_strdup(name);
        /* some default security attributes might be needed */
        file_handle.security_attributes=0;
-       file_handle.fileaccess=convert_from_flags(flags);
 
        /* Apparently input handles can't be written to.  (I don't
         * know if output or error handles can't be read from.)
@@ -101,9 +111,7 @@ gpointer _wapi_stdhandle_create (int fd, const gchar *name)
                return(INVALID_HANDLE_VALUE);
        }
        
-#ifdef DEBUG
-       g_message("%s: returning handle %p", __func__, handle);
-#endif
+       DEBUG("%s: returning handle %p", __func__, handle);
 
        return(handle);
 }