[w32file] Move MonoIO.Find{First,Next,Close} to managed
[mono.git] / mcs / class / corlib / System.IO / MonoIO.cs
index 9d816f40a5952a5e7edcb570a187b34eec2d5427..38c8cf3de735623fa52e6cd144ae626ceaed1fe7 100644 (file)
@@ -36,7 +36,7 @@ using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Threading;
 using Microsoft.Win32.SafeHandles;
-#if NET_2_1
+#if MOBILE
 using System.IO.IsolatedStorage;
 #endif
 
@@ -51,6 +51,8 @@ namespace System.IO
                public static readonly IntPtr
                        InvalidHandle = (IntPtr)(-1L);
 
+               static bool dump_handles = Environment.GetEnvironmentVariable ("MONO_DUMP_HANDLES_ON_ERROR_TOO_MANY_OPEN_FILES") != null;
+
                // error methods
                public static Exception GetException (MonoIOError error)
                {
@@ -89,6 +91,8 @@ namespace System.IO
                                return new FileNotFoundException (message, path);
 
                        case MonoIOError.ERROR_TOO_MANY_OPEN_FILES:
+                               if (dump_handles)
+                                       DumpHandles ();
                                return new IOException ("Too many open files", unchecked((int)0x80070000) | (int)error);
                                
                        case MonoIOError.ERROR_PATH_NOT_FOUND:
@@ -104,7 +108,7 @@ namespace System.IO
                                return new IOException (message, unchecked((int)0x80070000) | (int)error);
                        case MonoIOError.ERROR_INVALID_DRIVE:
                                message = String.Format ("Could not find the drive  '{0}'. The drive might not be ready or might not be mapped.", path);
-#if !NET_2_1
+#if !MOBILE
                                return new DriveNotFoundException (message);
 #else
                                return new IOException (message, unchecked((int)0x80070000) | (int)error);
@@ -151,6 +155,10 @@ namespace System.IO
                        case MonoIOError.ERROR_NOT_SAME_DEVICE:
                                message = "Source and destination are not on the same device";
                                return new IOException (message, unchecked((int)0x80070000) | (int)error);
+
+                       case MonoIOError.ERROR_DIRECTORY:
+                               message = "The directory name is invalid";
+                               return new IOException (message, unchecked((int)0x80070000) | (int)error);
                                
                        default:
                                message = String.Format ("Win32 IO returned {0}. Path: {1}", error, path);
@@ -166,9 +174,6 @@ namespace System.IO
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                public extern static bool RemoveDirectory (string path, out MonoIOError error);
 
-               [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern static string [] GetFileSystemEntries (string path, string path_with_pattern, int attrs, int mask, out MonoIOError error);
-
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                public extern static string GetCurrentDirectory (out MonoIOError error);
 
@@ -221,15 +226,16 @@ namespace System.IO
                //
                // Find file methods
                //
+
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern static string FindFirst (string path, string pattern, out FileAttributes result_attr, out MonoIOError error, out IntPtr handle);
-               
+               public extern static IntPtr FindFirstFile (string path_with_pattern, out string fileName, out int fileAttr, out int error);
+
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern static string FindNext (IntPtr handle, out FileAttributes result_attr, out MonoIOError error);
-               
+               public extern static bool FindNextFile (IntPtr hnd, out string fileName, out int fileAttr, out int error);
+
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern static int FindClose (IntPtr handle);
-               
+               public extern static bool FindCloseFile (IntPtr hnd);
+
                public static bool Exists (string path, out MonoIOError error)
                {
                        FileAttributes attrs = GetFileAttributes (path,
@@ -572,11 +578,11 @@ namespace System.IO
                // pipe handles
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern static bool CreatePipe (out IntPtr read_handle, out IntPtr write_handle);
+               public extern static bool CreatePipe (out IntPtr read_handle, out IntPtr write_handle, out MonoIOError error);
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                public extern static bool DuplicateHandle (IntPtr source_process_handle, IntPtr source_handle,
-                       IntPtr target_process_handle, out IntPtr target_handle, int access, int inherit, int options);
+                       IntPtr target_process_handle, out IntPtr target_handle, int access, int inherit, int options, out MonoIOError error);
 
                // path characters
 
@@ -599,6 +605,9 @@ namespace System.IO
                        [MethodImplAttribute (MethodImplOptions.InternalCall)]
                        get;
                }
+
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               extern static void DumpHandles ();
        }
 }