[reflection] Use coop handles for MonoMethod icalls (#4272)
[mono.git] / mono / metadata / file-io.c
index 17db2725b1d13c6171cf299b12b4bdb7f8ce9687..44fde40538cec2ac87acaa2d8a4f9468bc492daa 100644 (file)
@@ -459,6 +459,62 @@ incremental_find_check_match (IncrementalFind *handle, WIN32_FIND_DATA *data, Mo
        return TRUE;
 }
 
+HANDLE
+ves_icall_System_IO_MonoIO_FindFirstFile (MonoString *path_with_pattern, MonoString **file_name, gint32 *file_attr, gint32 *ioerror)
+{
+       HANDLE hnd;
+       WIN32_FIND_DATA data;
+       MonoError error;
+
+       hnd = FindFirstFile (mono_string_chars (path_with_pattern), &data);
+
+       if (hnd == INVALID_HANDLE_VALUE) {
+               *file_name = NULL;
+               *file_attr = 0;
+               *ioerror = GetLastError ();
+               return hnd;
+       }
+
+       mono_gc_wbarrier_generic_store (file_name, (MonoObject*) mono_string_from_utf16_checked (data.cFileName, &error));
+       mono_error_set_pending_exception (&error);
+
+       *file_attr = data.dwFileAttributes;
+       *ioerror = ERROR_SUCCESS;
+
+       return hnd;
+}
+
+MonoBoolean
+ves_icall_System_IO_MonoIO_FindNextFile (HANDLE hnd, MonoString **file_name, gint32 *file_attr, gint32 *ioerror)
+{
+       MonoBoolean res;
+       WIN32_FIND_DATA data;
+       MonoError error;
+
+       res = FindNextFile (hnd, &data);
+
+       if (res == FALSE) {
+               *file_name = NULL;
+               *file_attr = 0;
+               *ioerror = GetLastError ();
+               return res;
+       }
+
+       mono_gc_wbarrier_generic_store (file_name, (MonoObject*) mono_string_from_utf16_checked (data.cFileName, &error));
+       mono_error_set_pending_exception (&error);
+
+       *file_attr = data.dwFileAttributes;
+       *ioerror = ERROR_SUCCESS;
+
+       return res;
+}
+
+MonoBoolean
+ves_icall_System_IO_MonoIO_FindCloseFile (HANDLE hnd)
+{
+       return FindClose (hnd);
+}
+
 /* FIXME make gc suspendable */
 MonoString *
 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,