2 * file-io.c: File IO internal calls
5 * Dick Porter (dick@ximian.com)
6 * Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
9 * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
10 * Copyright 2012 Xamarin Inc (http://www.xamarin.com)
21 #ifdef HAVE_SYS_STAT_H
24 #ifdef HAVE_SYS_TYPES_H
25 #include <sys/types.h>
28 #include <mono/metadata/object.h>
29 #include <mono/io-layer/io-layer.h>
30 #include <mono/metadata/file-io.h>
31 #include <mono/metadata/exception.h>
32 #include <mono/metadata/appdomain.h>
33 #include <mono/metadata/marshal.h>
34 #include <mono/utils/strenc.h>
35 #include <utils/mono-io-portability.h>
39 /* conversion functions */
41 static guint32 convert_mode(MonoFileMode mono_mode)
46 case FileMode_CreateNew:
55 case FileMode_OpenOrCreate:
58 case FileMode_Truncate:
59 mode=TRUNCATE_EXISTING;
65 g_warning("System.IO.FileMode has unknown value 0x%x",
74 static guint32 convert_access(MonoFileAccess mono_access)
82 case FileAccess_Write:
85 case FileAccess_ReadWrite:
86 access=GENERIC_READ|GENERIC_WRITE;
89 g_warning("System.IO.FileAccess has unknown value 0x%x",
98 static guint32 convert_share(MonoFileShare mono_share)
102 if (mono_share & FileShare_Read) {
103 share |= FILE_SHARE_READ;
105 if (mono_share & FileShare_Write) {
106 share |= FILE_SHARE_WRITE;
108 if (mono_share & FileShare_Delete) {
109 share |= FILE_SHARE_DELETE;
112 if (mono_share & ~(FileShare_Read|FileShare_Write|FileShare_Delete)) {
113 g_warning("System.IO.FileShare has unknown value 0x%x",
123 static guint32 convert_stdhandle(guint32 fd)
129 stdhandle=STD_INPUT_HANDLE;
132 stdhandle=STD_OUTPUT_HANDLE;
135 stdhandle=STD_ERROR_HANDLE;
138 g_warning("unknown standard file descriptor %d", fd);
139 stdhandle=STD_INPUT_HANDLE;
146 static guint32 convert_seekorigin(MonoSeekOrigin origin)
151 case SeekOrigin_Begin:
152 w32origin=FILE_BEGIN;
154 case SeekOrigin_Current:
155 w32origin=FILE_CURRENT;
161 g_warning("System.IO.SeekOrigin has unknown value 0x%x",
164 w32origin=FILE_CURRENT;
170 static gint64 convert_filetime (const FILETIME *filetime)
172 guint64 ticks = filetime->dwHighDateTime;
174 ticks += filetime->dwLowDateTime;
175 return (gint64)ticks;
178 static void convert_win32_file_attribute_data (const WIN32_FILE_ATTRIBUTE_DATA *data, MonoIOStat *stat)
180 stat->attributes = data->dwFileAttributes;
181 stat->creation_time = convert_filetime (&data->ftCreationTime);
182 stat->last_access_time = convert_filetime (&data->ftLastAccessTime);
183 stat->last_write_time = convert_filetime (&data->ftLastWriteTime);
184 stat->length = ((gint64)data->nFileSizeHigh << 32) | data->nFileSizeLow;
187 /* Managed file attributes have nearly but not quite the same values
188 * as the w32 equivalents.
190 static guint32 convert_attrs(MonoFileAttributes attrs)
192 if(attrs & FileAttributes_Encrypted) {
193 attrs |= FILE_ATTRIBUTE_ENCRYPTED;
200 * On Win32, GetFileAttributes|Ex () seems to try opening the file,
201 * which might lead to sharing violation errors, whereas FindFirstFile
202 * always succeeds. These 2 wrappers resort to FindFirstFile if
203 * GetFileAttributes|Ex () has failed.
206 get_file_attributes (const gunichar2 *path)
209 WIN32_FIND_DATA find_data;
213 res = GetFileAttributes (path);
217 error = GetLastError ();
219 if (error != ERROR_SHARING_VIOLATION)
222 find_handle = FindFirstFile (path, &find_data);
224 if (find_handle == INVALID_HANDLE_VALUE)
227 FindClose (find_handle);
229 return find_data.dwFileAttributes;
233 get_file_attributes_ex (const gunichar2 *path, WIN32_FILE_ATTRIBUTE_DATA *data)
236 WIN32_FIND_DATA find_data;
240 res = GetFileAttributesEx (path, GetFileExInfoStandard, data);
244 error = GetLastError ();
246 if (error != ERROR_SHARING_VIOLATION)
249 find_handle = FindFirstFile (path, &find_data);
251 if (find_handle == INVALID_HANDLE_VALUE)
254 FindClose (find_handle);
256 data->dwFileAttributes = find_data.dwFileAttributes;
257 data->ftCreationTime = find_data.ftCreationTime;
258 data->ftLastAccessTime = find_data.ftLastAccessTime;
259 data->ftLastWriteTime = find_data.ftLastWriteTime;
260 data->nFileSizeHigh = find_data.nFileSizeHigh;
261 data->nFileSizeLow = find_data.nFileSizeLow;
266 /* System.IO.MonoIO internal calls */
269 ves_icall_System_IO_MonoIO_CreateDirectory (MonoString *path, gint32 *error)
275 *error=ERROR_SUCCESS;
277 ret=CreateDirectory (mono_string_chars (path), NULL);
279 *error=GetLastError ();
286 ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error)
292 *error=ERROR_SUCCESS;
294 ret=RemoveDirectory (mono_string_chars (path));
296 *error=GetLastError ();
303 get_search_dir (MonoString *pattern)
308 p = mono_string_to_utf8 (pattern);
309 result = g_path_get_dirname (p);
315 ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
316 MonoString *path_with_pattern,
317 gint attrs, gint mask,
323 WIN32_FIND_DATA data;
326 gchar *utf8_path, *utf8_result, *full_name;
332 *error = ERROR_SUCCESS;
334 domain = mono_domain_get ();
335 mask = convert_attrs (mask);
336 attributes = get_file_attributes (mono_string_chars (path));
337 if (attributes != -1) {
338 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
339 *error = ERROR_INVALID_NAME;
343 *error = GetLastError ();
347 find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data);
348 if (find_handle == INVALID_HANDLE_VALUE) {
349 gint32 find_error = GetLastError ();
351 if (find_error == ERROR_FILE_NOT_FOUND || find_error == ERROR_NO_MORE_FILES) {
352 /* No files, so just return an empty array */
360 utf8_path = get_search_dir (path_with_pattern);
361 names = g_ptr_array_new ();
364 if ((data.cFileName[0] == '.' && data.cFileName[1] == 0) ||
365 (data.cFileName[0] == '.' && data.cFileName[1] == '.' && data.cFileName[2] == 0)) {
369 if ((data.dwFileAttributes & mask) == attrs) {
370 utf8_result = g_utf16_to_utf8 (data.cFileName, -1, NULL, NULL, NULL);
371 if (utf8_result == NULL) {
375 full_name = g_build_filename (utf8_path, utf8_result, NULL);
376 g_ptr_array_add (names, full_name);
378 g_free (utf8_result);
380 } while(FindNextFile (find_handle, &data));
382 if (FindClose (find_handle) == FALSE) {
383 *error = GetLastError ();
386 result = mono_array_new (domain, mono_defaults.string_class, names->len);
387 for (i = 0; i < names->len; i++) {
388 mono_array_setref (result, i, mono_string_new (domain, g_ptr_array_index (names, i)));
392 for (i = 0; i < names->len; i++) {
393 g_free (g_ptr_array_index (names, i));
395 g_ptr_array_free (names, TRUE);
399 // If there's no array and no error, then return an empty array.
400 if (result == NULL && *error == ERROR_SUCCESS)
401 result = mono_array_new (domain, mono_defaults.string_class, 0);
413 incremental_find_check_match (IncrementalFind *handle, WIN32_FIND_DATA *data, MonoString **result)
418 if ((data->cFileName[0] == '.' && data->cFileName[1] == 0) || (data->cFileName[0] == '.' && data->cFileName[1] == '.' && data->cFileName[2] == 0))
421 utf8_result = g_utf16_to_utf8 (data->cFileName, -1, NULL, NULL, NULL);
422 if (utf8_result == NULL)
425 full_name = g_build_filename (handle->utf8_path, utf8_result, NULL);
426 g_free (utf8_result);
427 *result = mono_string_new (mono_domain_get (), full_name);
434 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
435 MonoString *path_with_pattern,
436 gint32 *result_attr, gint32 *error,
439 WIN32_FIND_DATA data;
441 IncrementalFind *ifh;
444 *error = ERROR_SUCCESS;
446 find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data);
448 if (find_handle == INVALID_HANDLE_VALUE) {
449 gint32 find_error = GetLastError ();
452 if (find_error == ERROR_FILE_NOT_FOUND)
459 ifh = g_new (IncrementalFind, 1);
460 ifh->find_handle = find_handle;
461 ifh->utf8_path = mono_string_to_utf8 (path);
462 ifh->domain = mono_domain_get ();
465 while (incremental_find_check_match (ifh, &data, &result) == 0){
466 if (FindNextFile (find_handle, &data) == FALSE){
467 int e = GetLastError ();
468 if (e != ERROR_NO_MORE_FILES)
473 *result_attr = data.dwFileAttributes;
479 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint32 *error)
481 IncrementalFind *ifh = handle;
482 WIN32_FIND_DATA data;
485 *error = ERROR_SUCCESS;
487 if (FindNextFile (ifh->find_handle, &data) == FALSE){
488 int e = GetLastError ();
489 if (e != ERROR_NO_MORE_FILES)
493 } while (incremental_find_check_match (ifh, &data, &result) == 0);
495 *result_attr = data.dwFileAttributes;
500 ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
502 IncrementalFind *ifh = handle;
505 if (FindClose (ifh->find_handle) == FALSE){
506 error = GetLastError ();
508 error = ERROR_SUCCESS;
509 g_free (ifh->utf8_path);
516 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *error)
524 len = MAX_PATH + 1; /*FIXME this is too smal under most unix systems.*/
525 buf = g_new (gunichar2, len);
527 *error=ERROR_SUCCESS;
530 res_len = GetCurrentDirectory (len, buf);
531 if (res_len > len) { /*buf is too small.*/
532 int old_res_len = res_len;
534 buf = g_new (gunichar2, res_len);
535 res_len = GetCurrentDirectory (res_len, buf) == old_res_len;
543 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
545 *error=GetLastError ();
553 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
560 *error=ERROR_SUCCESS;
562 ret=SetCurrentDirectory (mono_string_chars (path));
564 *error=GetLastError ();
571 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest,
578 *error=ERROR_SUCCESS;
580 ret=MoveFile (mono_string_chars (path), mono_string_chars (dest));
582 *error=GetLastError ();
589 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
590 MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
594 gunichar2 *utf16_sourceFileName = NULL, *utf16_destinationFileName = NULL, *utf16_destinationBackupFileName = NULL;
595 guint32 replaceFlags = REPLACEFILE_WRITE_THROUGH;
600 utf16_sourceFileName = mono_string_chars (sourceFileName);
601 if (destinationFileName)
602 utf16_destinationFileName = mono_string_chars (destinationFileName);
603 if (destinationBackupFileName)
604 utf16_destinationBackupFileName = mono_string_chars (destinationBackupFileName);
606 *error = ERROR_SUCCESS;
607 if (ignoreMetadataErrors)
608 replaceFlags |= REPLACEFILE_IGNORE_MERGE_ERRORS;
610 /* FIXME: source and destination file names must not be NULL, but apparently they might be! */
611 ret = ReplaceFile (utf16_destinationFileName, utf16_sourceFileName, utf16_destinationBackupFileName,
612 replaceFlags, NULL, NULL);
614 *error = GetLastError ();
620 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
621 MonoBoolean overwrite, gint32 *error)
627 *error=ERROR_SUCCESS;
629 ret=CopyFile (mono_string_chars (path), mono_string_chars (dest), !overwrite);
631 *error=GetLastError ();
638 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error)
644 *error=ERROR_SUCCESS;
646 ret=DeleteFile (mono_string_chars (path));
648 *error=GetLastError ();
655 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error)
661 *error=ERROR_SUCCESS;
663 ret=get_file_attributes (mono_string_chars (path));
666 * The definition of INVALID_FILE_ATTRIBUTES in the cygwin win32
667 * headers is wrong, hence this temporary workaround.
669 * http://cygwin.com/ml/cygwin/2003-09/msg01771.html
672 /* if(ret==INVALID_FILE_ATTRIBUTES) { */
673 *error=GetLastError ();
680 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
687 *error=ERROR_SUCCESS;
689 ret=SetFileAttributes (mono_string_chars (path),
690 convert_attrs (attrs));
692 *error=GetLastError ();
699 ves_icall_System_IO_MonoIO_GetFileType (MonoSafeHandle *safeHandle, gint32 *error)
705 *error=ERROR_SUCCESS;
707 ret=GetFileType (safeHandle->handle);
708 if(ret==FILE_TYPE_UNKNOWN) {
709 /* Not necessarily an error, but the caller will have
710 * to decide based on the error value.
712 *error=GetLastError ();
719 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat,
723 WIN32_FILE_ATTRIBUTE_DATA data;
727 *error=ERROR_SUCCESS;
729 result = get_file_attributes_ex (mono_string_chars (path), &data);
732 convert_win32_file_attribute_data (&data, stat);
734 *error=GetLastError ();
735 memset (stat, 0, sizeof (MonoIOStat));
742 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
743 gint32 access_mode, gint32 share, gint32 options,
747 int attributes, attrs;
748 gunichar2 *chars = mono_string_chars (filename);
752 *error=ERROR_SUCCESS;
755 if (options & FileOptions_Encrypted)
756 attributes = FILE_ATTRIBUTE_ENCRYPTED;
758 attributes = FILE_ATTRIBUTE_NORMAL;
759 if (options & FileOptions_DeleteOnClose)
760 attributes |= FILE_FLAG_DELETE_ON_CLOSE;
761 if (options & FileOptions_SequentialScan)
762 attributes |= FILE_FLAG_SEQUENTIAL_SCAN;
763 if (options & FileOptions_RandomAccess)
764 attributes |= FILE_FLAG_RANDOM_ACCESS;
766 if (options & FileOptions_Temporary)
767 attributes |= FILE_ATTRIBUTE_TEMPORARY;
769 /* Not sure if we should set FILE_FLAG_OVERLAPPED, how does this mix with the "Async" bool here? */
770 if (options & FileOptions_Asynchronous)
771 attributes |= FILE_FLAG_OVERLAPPED;
773 if (options & FileOptions_WriteThrough)
774 attributes |= FILE_FLAG_WRITE_THROUGH;
776 attributes = FILE_ATTRIBUTE_NORMAL;
778 /* If we're opening a directory we need to set the extra flag
780 attrs = get_file_attributes (chars);
781 if (attrs != INVALID_FILE_ATTRIBUTES) {
782 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
783 attributes |= FILE_FLAG_BACKUP_SEMANTICS;
787 ret=CreateFile (chars, convert_access (access_mode),
788 convert_share (share), NULL, convert_mode (mode),
790 if(ret==INVALID_HANDLE_VALUE) {
791 *error=GetLastError ();
798 ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error)
804 *error=ERROR_SUCCESS;
806 ret=CloseHandle (handle);
808 *error=GetLastError ();
815 ves_icall_System_IO_MonoIO_Read (MonoSafeHandle *safeHandle, MonoArray *dest,
816 gint32 dest_offset, gint32 count,
825 *error=ERROR_SUCCESS;
827 MONO_CHECK_ARG_NULL (dest);
829 if (dest_offset > mono_array_length (dest) - count)
830 mono_raise_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
832 buffer = mono_array_addr (dest, guchar, dest_offset);
833 result = ReadFile (safeHandle->handle, buffer, count, &n, NULL);
836 *error=GetLastError ();
844 ves_icall_System_IO_MonoIO_Write (MonoSafeHandle *safeHandle, MonoArray *src,
845 gint32 src_offset, gint32 count,
854 *error=ERROR_SUCCESS;
856 MONO_CHECK_ARG_NULL (src);
858 if (src_offset > mono_array_length (src) - count)
859 mono_raise_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
861 buffer = mono_array_addr (src, guchar, src_offset);
862 result = WriteFile (safeHandle->handle, buffer, count, &n, NULL);
865 *error=GetLastError ();
873 ves_icall_System_IO_MonoIO_Seek (MonoSafeHandle *safeHandle, gint64 offset, gint32 origin,
880 *error=ERROR_SUCCESS;
882 offset_hi = offset >> 32;
883 offset = SetFilePointer (safeHandle->handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
884 convert_seekorigin (origin));
886 if(offset==INVALID_SET_FILE_POINTER) {
887 *error=GetLastError ();
890 return offset | ((gint64)offset_hi << 32);
894 ves_icall_System_IO_MonoIO_Flush (MonoSafeHandle *safeHandle, gint32 *error)
900 *error=ERROR_SUCCESS;
902 ret=FlushFileBuffers (safeHandle->handle);
904 *error=GetLastError ();
911 ves_icall_System_IO_MonoIO_GetLength (MonoSafeHandle *safeHandle, gint32 *error)
918 *error=ERROR_SUCCESS;
920 length = GetFileSize (safeHandle->handle, &length_hi);
921 if(length==INVALID_FILE_SIZE) {
922 *error=GetLastError ();
925 return length | ((gint64)length_hi << 32);
929 ves_icall_System_IO_MonoIO_SetLength (MonoSafeHandle *safeHandle, gint64 length,
932 gint64 offset, offset_set;
939 *error=ERROR_SUCCESS;
941 /* save file pointer */
944 offset = SetFilePointer (safeHandle->handle, 0, &offset_hi, FILE_CURRENT);
945 if(offset==INVALID_SET_FILE_POINTER) {
946 *error=GetLastError ();
950 /* extend or truncate */
952 length_hi = length >> 32;
953 offset_set=SetFilePointer (safeHandle->handle, length & 0xFFFFFFFF, &length_hi,
955 if(offset_set==INVALID_SET_FILE_POINTER) {
956 *error=GetLastError ();
960 result = SetEndOfFile (safeHandle->handle);
962 *error=GetLastError ();
966 /* restore file pointer */
968 offset_set=SetFilePointer (safeHandle->handle, offset & 0xFFFFFFFF, &offset_hi,
970 if(offset_set==INVALID_SET_FILE_POINTER) {
971 *error=GetLastError ();
979 ves_icall_System_IO_MonoIO_SetFileTime (MonoSafeHandle *safeHandle, gint64 creation_time,
980 gint64 last_access_time,
981 gint64 last_write_time, gint32 *error)
984 const FILETIME *creation_filetime;
985 const FILETIME *last_access_filetime;
986 const FILETIME *last_write_filetime;
990 *error=ERROR_SUCCESS;
992 if (creation_time < 0)
993 creation_filetime = NULL;
995 creation_filetime = (FILETIME *)&creation_time;
997 if (last_access_time < 0)
998 last_access_filetime = NULL;
1000 last_access_filetime = (FILETIME *)&last_access_time;
1002 if (last_write_time < 0)
1003 last_write_filetime = NULL;
1005 last_write_filetime = (FILETIME *)&last_write_time;
1007 ret=SetFileTime (safeHandle->handle, creation_filetime, last_access_filetime, last_write_filetime);
1009 *error=GetLastError ();
1016 ves_icall_System_IO_MonoIO_get_ConsoleOutput ()
1018 MONO_ARCH_SAVE_REGS;
1020 return GetStdHandle (STD_OUTPUT_HANDLE);
1024 ves_icall_System_IO_MonoIO_get_ConsoleInput ()
1026 MONO_ARCH_SAVE_REGS;
1028 return GetStdHandle (STD_INPUT_HANDLE);
1032 ves_icall_System_IO_MonoIO_get_ConsoleError ()
1034 MONO_ARCH_SAVE_REGS;
1036 return GetStdHandle (STD_ERROR_HANDLE);
1040 ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle,
1041 HANDLE *write_handle)
1043 SECURITY_ATTRIBUTES attr;
1046 MONO_ARCH_SAVE_REGS;
1048 attr.nLength=sizeof(SECURITY_ATTRIBUTES);
1049 attr.bInheritHandle=TRUE;
1050 attr.lpSecurityDescriptor=NULL;
1052 ret=CreatePipe (read_handle, write_handle, &attr, 0);
1054 /* FIXME: throw an exception? */
1061 MonoBoolean ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle,
1062 HANDLE source_handle, HANDLE target_process_handle, HANDLE *target_handle,
1063 gint32 access, gint32 inherit, gint32 options)
1065 /* This is only used on Windows */
1068 MONO_ARCH_SAVE_REGS;
1070 ret=DuplicateHandle (source_process_handle, source_handle, target_process_handle, target_handle, access, inherit, options);
1072 /* FIXME: throw an exception? */
1080 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
1082 #if defined (TARGET_WIN32)
1083 return (gunichar2) ':'; /* colon */
1085 return (gunichar2) '/'; /* forward slash */
1090 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
1092 #if defined (TARGET_WIN32)
1093 return (gunichar2) '\\'; /* backslash */
1095 return (gunichar2) '/'; /* forward slash */
1100 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
1102 #if defined (TARGET_WIN32)
1103 return (gunichar2) '/'; /* forward slash */
1105 if (IS_PORTABILITY_SET)
1106 return (gunichar2) '\\'; /* backslash */
1108 return (gunichar2) '/'; /* forward slash */
1113 ves_icall_System_IO_MonoIO_get_PathSeparator ()
1115 #if defined (TARGET_WIN32)
1116 return (gunichar2) ';'; /* semicolon */
1118 return (gunichar2) ':'; /* colon */
1122 static const gunichar2
1123 invalid_path_chars [] = {
1124 #if defined (TARGET_WIN32)
1125 0x0022, /* double quote, which seems allowed in MS.NET but should be rejected */
1126 0x003c, /* less than */
1127 0x003e, /* greater than */
1144 ves_icall_System_IO_MonoIO_get_InvalidPathChars ()
1150 MONO_ARCH_SAVE_REGS;
1152 domain = mono_domain_get ();
1153 n = sizeof (invalid_path_chars) / sizeof (gunichar2);
1154 chars = mono_array_new (domain, mono_defaults.char_class, n);
1156 for (i = 0; i < n; ++ i)
1157 mono_array_set (chars, gunichar2, i, invalid_path_chars [i]);
1163 ves_icall_System_IO_MonoIO_GetTempPath (MonoString **mono_name)
1168 name=g_new0 (gunichar2, 256);
1170 ret=GetTempPath (256, name);
1172 /* Buffer was too short. Try again... */
1174 name=g_new0 (gunichar2, ret+2); /* include the terminator */
1175 ret=GetTempPath (ret, name);
1180 g_message ("%s: Temp path is [%s] (len %d)", __func__, name, ret);
1183 mono_gc_wbarrier_generic_store ((gpointer) mono_name,
1184 (MonoObject*) mono_string_new_utf16 (mono_domain_get (), name, ret));
1192 void ves_icall_System_IO_MonoIO_Lock (MonoSafeHandle *safeHandle, gint64 position,
1193 gint64 length, gint32 *error)
1197 *error=ERROR_SUCCESS;
1199 ret=LockFile (safeHandle->handle, position & 0xFFFFFFFF, position >> 32,
1200 length & 0xFFFFFFFF, length >> 32);
1202 *error = GetLastError ();
1206 void ves_icall_System_IO_MonoIO_Unlock (MonoSafeHandle *safeHandle, gint64 position,
1207 gint64 length, gint32 *error)
1211 *error=ERROR_SUCCESS;
1213 ret=UnlockFile (safeHandle->handle, position & 0xFFFFFFFF, position >> 32,
1214 length & 0xFFFFFFFF, length >> 32);
1216 *error = GetLastError ();
1220 //Support for io-layer free mmap'd files.
1222 #if defined (TARGET_IOS) || defined (TARGET_ANDROID)
1225 mono_filesize_from_path (MonoString *string)
1229 char *path = mono_string_to_utf8 (string);
1231 if (stat (path, &buf) == -1)
1234 res = (gint64)buf.st_size;
1241 mono_filesize_from_fd (int fd)
1245 if (fstat (fd, &buf) == -1)
1248 return (gint64)buf.st_size;