Update COPYING.LIB
[mono.git] / mono / metadata / file-io.c
index b193e0a54945d373379c6dc1c990ea4855eaf8b6..c0d0f1c11e32f01631f4ab9228bbfbd3aee26d0b 100644 (file)
@@ -8,6 +8,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)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include <config.h>
@@ -190,7 +191,7 @@ static void convert_win32_file_attribute_data (const WIN32_FILE_ATTRIBUTE_DATA *
 static guint32 convert_attrs(MonoFileAttributes attrs)
 {
        if(attrs & FileAttributes_Encrypted) {
-               attrs |= FILE_ATTRIBUTE_ENCRYPTED;
+               attrs = (MonoFileAttributes)(attrs | FILE_ATTRIBUTE_ENCRYPTED);
        }
        
        return(attrs);
@@ -324,7 +325,7 @@ get_filesystem_entries (const gunichar2 *path,
        gchar *utf8_path = NULL, *utf8_result, *full_name;
        gint32 attributes;
 
-       mask = convert_attrs (mask);
+       mask = convert_attrs ((MonoFileAttributes)mask);
        attributes = get_file_attributes (path);
        if (attributes != -1) {
                if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
@@ -415,7 +416,7 @@ ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
 
        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)));
+               mono_array_setref (result, i, mono_string_new (domain, (const char *)g_ptr_array_index (names, i)));
                g_free (g_ptr_array_index (names, i));
        }
        g_ptr_array_free (names, TRUE);
@@ -499,7 +500,7 @@ ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
 MonoString *
 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint32 *error)
 {
-       IncrementalFind *ifh = handle;
+       IncrementalFind *ifh = (IncrementalFind *)handle;
        WIN32_FIND_DATA data;
        MonoString *result;
 
@@ -520,7 +521,7 @@ ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint3
 int
 ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
 {
-       IncrementalFind *ifh = handle;
+       IncrementalFind *ifh = (IncrementalFind *)handle;
        gint32 error;
 
        MONO_PREPARE_BLOCKING;
@@ -536,8 +537,9 @@ ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
 }
 
 MonoString *
-ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *error)
+ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *io_error)
 {
+       MonoError error;
        MonoString *result;
        gunichar2 *buf;
        int len, res_len;
@@ -545,7 +547,8 @@ ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *error)
        len = MAX_PATH + 1; /*FIXME this is too smal under most unix systems.*/
        buf = g_new (gunichar2, len);
        
-       *error=ERROR_SUCCESS;
+       mono_error_init (&error);
+       *io_error=ERROR_SUCCESS;
        result = NULL;
 
        res_len = GetCurrentDirectory (len, buf);
@@ -561,12 +564,13 @@ ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *error)
                while (buf [len])
                        ++ len;
 
-               result = mono_string_new_utf16 (mono_domain_get (), buf, len);
+               result = mono_string_new_utf16_checked (mono_domain_get (), buf, len, &error);
        } else {
-               *error=GetLastError ();
+               *io_error=GetLastError ();
        }
 
        g_free (buf);
+       mono_error_raise_exception (&error);
        return result;
 }
 
@@ -705,7 +709,7 @@ ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
        *error=ERROR_SUCCESS;
        
        ret=SetFileAttributes (mono_string_chars (path),
-                              convert_attrs (attrs));
+               convert_attrs ((MonoFileAttributes)attrs));
        if(ret==FALSE) {
                *error=GetLastError ();
        }
@@ -803,8 +807,8 @@ ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
                }
        }
        
-       ret=CreateFile (chars, convert_access (access_mode),
-                       convert_share (share), NULL, convert_mode (mode),
+       ret=CreateFile (chars, convert_access ((MonoFileAccess)access_mode),
+                       convert_share ((MonoFileShare)share), NULL, convert_mode ((MonoFileMode)mode),
                        attributes, NULL);
        if(ret==INVALID_HANDLE_VALUE) {
                *error=GetLastError ();
@@ -905,7 +909,7 @@ ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
        
        offset_hi = offset >> 32;
        offset = SetFilePointer (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
-                                convert_seekorigin (origin));
+                                convert_seekorigin ((MonoSeekOrigin)origin));
 
        if(offset==INVALID_SET_FILE_POINTER) {
                *error=GetLastError ();
@@ -1252,3 +1256,12 @@ mono_filesize_from_fd (int fd)
 }
 
 #endif
+
+void _wapi_handle_dump (void);
+
+void ves_icall_System_IO_MonoIO_DumpHandles (void)
+{
+#ifndef HOST_WIN32
+       _wapi_handle_dump ();
+#endif
+}