return(w32origin);
}
-static gint64 convert_filetime (const FILETIME *filetime)
-{
- return (gint64) ((((guint64) filetime->dwHighDateTime) << 32) + filetime->dwLowDateTime);
-}
-
/* Managed file attributes have nearly but not quite the same values
* as the w32 equivalents.
*/
return(attrs);
}
-/*
- * On Win32, mono_w32file_get_attributes|_ex () seems to try opening the file,
- * which might lead to sharing violation errors, whereas mono_w32file_find_first
- * always succeeds. These 2 wrappers resort to mono_w32file_find_first if
- * mono_w32file_get_attributes|_ex () has failed.
- */
-static guint32
-get_file_attributes (const gunichar2 *path)
-{
- guint32 res;
- WIN32_FIND_DATA find_data;
- HANDLE find_handle;
- gint32 error;
-
- res = mono_w32file_get_attributes (path);
- if (res != -1)
- return res;
-
- error = mono_w32error_get_last ();
-
- if (error != ERROR_SHARING_VIOLATION)
- return res;
-
- find_handle = mono_w32file_find_first (path, &find_data);
-
- if (find_handle == INVALID_HANDLE_VALUE)
- return res;
-
- mono_w32file_find_close (find_handle);
-
- return find_data.dwFileAttributes;
-}
-
-static gboolean
-get_file_attributes_ex (const gunichar2 *path, MonoIOStat *stat)
-{
- gboolean res;
- WIN32_FIND_DATA find_data;
- HANDLE find_handle;
- gint32 error;
-
- res = mono_w32file_get_attributes_ex (path, stat);
- if (res)
- return TRUE;
-
- error = mono_w32error_get_last ();
- if (error != ERROR_SHARING_VIOLATION)
- return FALSE;
-
- find_handle = mono_w32file_find_first (path, &find_data);
-
- if (find_handle == INVALID_HANDLE_VALUE)
- return FALSE;
-
- mono_w32file_find_close (find_handle);
-
- stat->attributes = find_data.dwFileAttributes;
- stat->creation_time = convert_filetime (&find_data.ftCreationTime);
- stat->last_access_time = convert_filetime (&find_data.ftLastAccessTime);
- stat->last_write_time = convert_filetime (&find_data.ftLastWriteTime);
- stat->length = ((gint64)find_data.nFileSizeHigh << 32) | find_data.nFileSizeLow;
- return TRUE;
-}
-
/* System.IO.MonoIO internal calls */
MonoBoolean
return(ret);
}
-typedef struct {
- MonoDomain *domain;
- gchar *utf8_path;
- HANDLE find_handle;
-} IncrementalFind;
-
-static gboolean
-incremental_find_check_match (IncrementalFind *handle, WIN32_FIND_DATA *data, MonoString **result, MonoError *error)
-{
- error_init (error);
- gchar *utf8_result;
- gchar *full_name;
-
- if ((data->cFileName[0] == '.' && data->cFileName[1] == 0) || (data->cFileName[0] == '.' && data->cFileName[1] == '.' && data->cFileName[2] == 0))
- return FALSE;
-
- utf8_result = g_utf16_to_utf8 (data->cFileName, -1, NULL, NULL, NULL);
- if (utf8_result == NULL)
- return FALSE;
-
- full_name = g_build_filename (handle->utf8_path, utf8_result, NULL);
- g_free (utf8_result);
- *result = mono_string_new_checked (mono_domain_get (), full_name, error);
- g_free (full_name);
- if (!is_ok (error))
- return FALSE;
-
- return TRUE;
-}
-
HANDLE
ves_icall_System_IO_MonoIO_FindFirstFile (MonoString *path_with_pattern, MonoString **file_name, gint32 *file_attr, gint32 *ioerror)
{
return mono_w32file_find_close (hnd);
}
-/* FIXME make gc suspendable */
-MonoString *
-ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
- MonoString *path_with_pattern,
- gint32 *result_attr, gint32 *ioerror,
- gpointer *handle)
-{
- MonoError error;
- WIN32_FIND_DATA data;
- HANDLE find_handle;
- IncrementalFind *ifh;
- MonoString *result;
-
- *ioerror = ERROR_SUCCESS;
-
- find_handle = mono_w32file_find_first (mono_string_chars (path_with_pattern), &data);
-
- if (find_handle == INVALID_HANDLE_VALUE) {
- gint32 find_error = mono_w32error_get_last ();
- *handle = NULL;
-
- if (find_error == ERROR_FILE_NOT_FOUND)
- return NULL;
-
- *ioerror = find_error;
- return NULL;
- }
-
- ifh = g_new (IncrementalFind, 1);
- ifh->find_handle = find_handle;
- ifh->utf8_path = mono_string_to_utf8_checked (path, &error);
- if (mono_error_set_pending_exception (&error)) {
- mono_w32file_find_close (find_handle);
- g_free (ifh);
- return NULL;
- }
- ifh->domain = mono_domain_get ();
- *handle = ifh;
-
- while (incremental_find_check_match (ifh, &data, &result, &error) == 0){
- if (!is_ok (&error)) {
- mono_error_set_pending_exception (&error);
- return NULL;
- }
- if (mono_w32file_find_next (find_handle, &data) == FALSE){
- int e = mono_w32error_get_last ();
- if (e != ERROR_NO_MORE_FILES)
- *ioerror = e;
- return NULL;
- }
- }
- *result_attr = data.dwFileAttributes;
-
- return result;
-}
-
-/* FIXME make gc suspendable */
-MonoString *
-ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint32 *ioerror)
-{
- MonoError error;
- IncrementalFind *ifh = (IncrementalFind *)handle;
- WIN32_FIND_DATA data;
- MonoString *result;
-
- error_init (&error);
- *ioerror = ERROR_SUCCESS;
- do {
- if (!is_ok (&error)) {
- mono_error_set_pending_exception (&error);
- return NULL;
- }
- if (mono_w32file_find_next (ifh->find_handle, &data) == FALSE){
- int e = mono_w32error_get_last ();
- if (e != ERROR_NO_MORE_FILES)
- *ioerror = e;
- return NULL;
- }
- } while (incremental_find_check_match (ifh, &data, &result, &error) == 0);
-
- *result_attr = data.dwFileAttributes;
- return result;
-}
-
-int
-ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
-{
- IncrementalFind *ifh = (IncrementalFind *)handle;
- gint32 error;
-
- if (mono_w32file_find_close (ifh->find_handle) == FALSE){
- error = mono_w32error_get_last ();
- } else
- error = ERROR_SUCCESS;
- g_free (ifh->utf8_path);
- g_free (ifh);
-
- return error;
-}
-
MonoString *
ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *io_error)
{
gint32 ret;
*error=ERROR_SUCCESS;
- ret=get_file_attributes (mono_string_chars (path));
+ ret = mono_w32file_get_attributes (mono_string_chars (path));
/*
* The definition of INVALID_FILE_ATTRIBUTES in the cygwin win32
*error=ERROR_SUCCESS;
- result = get_file_attributes_ex (mono_string_chars (path), stat);
+ result = mono_w32file_get_attributes_ex (mono_string_chars (path), stat);
if (!result) {
*error=mono_w32error_get_last ();
/* If we're opening a directory we need to set the extra flag
*/
- attrs = get_file_attributes (chars);
+ attrs = mono_w32file_get_attributes (chars);
if (attrs != INVALID_FILE_ATTRIBUTES) {
if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
attributes |= FILE_FLAG_BACKUP_SEMANTICS;