Merge pull request #487 from mayerwin/patch-1
[mono.git] / mono / metadata / file-io.c
index efb353513e64a62695d7a857690946bf81d78919..ac7b0c41cc3f4bac4f2aa4e50c6bf68ef12d9c7b 100644 (file)
@@ -7,6 +7,7 @@
  *
  * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
  * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
+ * Copyright 2012 Xamarin Inc (http://www.xamarin.com)
  */
 
 #include <config.h>
@@ -327,6 +328,7 @@ ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
        
        MONO_ARCH_SAVE_REGS;
 
+       result = NULL;
        *error = ERROR_SUCCESS;
 
        domain = mono_domain_get ();
@@ -335,11 +337,11 @@ ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
        if (attributes != -1) {
                if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
                        *error = ERROR_INVALID_NAME;
-                       return (NULL);
+                       goto leave;
                }
        } else {
                *error = GetLastError ();
-               return (NULL);
+               goto leave;
        }
        
        find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data);
@@ -348,15 +350,11 @@ ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
                
                if (find_error == ERROR_FILE_NOT_FOUND || find_error == ERROR_NO_MORE_FILES) {
                        /* No files, so just return an empty array */
-                       result = mono_array_new (domain,
-                                                mono_defaults.string_class,
-                                                0);
-
-                       return(result);
+                       goto leave;
                }
                
                *error = find_error;
-               return(NULL);
+               goto leave;
        }
 
        utf8_path = get_search_dir (path_with_pattern);
@@ -396,7 +394,12 @@ ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
        }
        g_ptr_array_free (names, TRUE);
        g_free (utf8_path);
-       
+
+leave:
+       // If there's no array and no error, then return an empty array.
+       if (result == NULL && *error == ERROR_SUCCESS)
+               result = mono_array_new (domain, mono_defaults.string_class, 0);
+
        return result;
 }
 
@@ -1215,7 +1218,7 @@ void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
 
 //Support for io-layer free mmap'd files.
 
-#if (defined (__MACH__) && defined (TARGET_ARM)) || defined (TARGET_ANDROID)
+#if defined (TARGET_IOS) || defined (TARGET_ANDROID)
 
 gint64
 mono_filesize_from_path (MonoString *string)