Update COPYING.LIB
[mono.git] / mono / metadata / file-io.c
index 108c0c9d719513b668e5aa4119f88f3016eaa05d..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>
@@ -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;
 }
 
@@ -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,
-                                (WapiSeekMethod)convert_seekorigin ((MonoSeekOrigin)origin));
+                                convert_seekorigin ((MonoSeekOrigin)origin));
 
        if(offset==INVALID_SET_FILE_POINTER) {
                *error=GetLastError ();