+MonoArray *
+ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
+ MonoString *path_with_pattern,
+ gint attrs, gint mask,
+ gint32 *error)
+{
+ MonoDomain *domain = mono_domain_get ();
+ MonoArray *result;
+ int i;
+ GPtrArray *names;
+
+ *error = ERROR_SUCCESS;
+
+ MONO_PREPARE_BLOCKING
+ names = get_filesystem_entries (path, path_with_pattern, attrs, mask, error);
+ MONO_FINISH_BLOCKING
+
+ if (!names) {
+ // If there's no array and no error, then return an empty array.
+ if (*error == ERROR_SUCCESS)
+ return mono_array_new (domain, mono_defaults.string_class, 0);
+ return NULL;
+ }
+
+ result = mono_array_new (domain, mono_defaults.string_class, names->len);
+ for (i = 0; i < names->len; i++) {
+ mono_array_setref (result, i, mono_string_new (domain, g_ptr_array_index (names, i)));
+ g_free (g_ptr_array_index (names, i));
+ }
+ g_ptr_array_free (names, TRUE);