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)
11 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
22 #ifdef HAVE_SYS_STAT_H
25 #ifdef HAVE_SYS_TYPES_H
26 #include <sys/types.h>
29 #include <mono/metadata/object.h>
30 #include <mono/io-layer/io-layer.h>
31 #include <mono/metadata/file-io.h>
32 #include <mono/metadata/exception.h>
33 #include <mono/metadata/appdomain.h>
34 #include <mono/metadata/marshal.h>
35 #include <mono/utils/strenc.h>
36 #include <utils/mono-io-portability.h>
40 /* conversion functions */
42 static guint32 convert_mode(MonoFileMode mono_mode)
47 case FileMode_CreateNew:
56 case FileMode_OpenOrCreate:
59 case FileMode_Truncate:
60 mode=TRUNCATE_EXISTING;
66 g_warning("System.IO.FileMode has unknown value 0x%x",
75 static guint32 convert_access(MonoFileAccess mono_access)
83 case FileAccess_Write:
86 case FileAccess_ReadWrite:
87 access=GENERIC_READ|GENERIC_WRITE;
90 g_warning("System.IO.FileAccess has unknown value 0x%x",
99 static guint32 convert_share(MonoFileShare mono_share)
103 if (mono_share & FileShare_Read) {
104 share |= FILE_SHARE_READ;
106 if (mono_share & FileShare_Write) {
107 share |= FILE_SHARE_WRITE;
109 if (mono_share & FileShare_Delete) {
110 share |= FILE_SHARE_DELETE;
113 if (mono_share & ~(FileShare_Read|FileShare_Write|FileShare_Delete)) {
114 g_warning("System.IO.FileShare has unknown value 0x%x",
124 static guint32 convert_stdhandle(guint32 fd)
130 stdhandle=STD_INPUT_HANDLE;
133 stdhandle=STD_OUTPUT_HANDLE;
136 stdhandle=STD_ERROR_HANDLE;
139 g_warning("unknown standard file descriptor %d", fd);
140 stdhandle=STD_INPUT_HANDLE;
147 static guint32 convert_seekorigin(MonoSeekOrigin origin)
152 case SeekOrigin_Begin:
153 w32origin=FILE_BEGIN;
155 case SeekOrigin_Current:
156 w32origin=FILE_CURRENT;
162 g_warning("System.IO.SeekOrigin has unknown value 0x%x",
165 w32origin=FILE_CURRENT;
171 static gint64 convert_filetime (const FILETIME *filetime)
173 guint64 ticks = filetime->dwHighDateTime;
175 ticks += filetime->dwLowDateTime;
176 return (gint64)ticks;
179 static void convert_win32_file_attribute_data (const WIN32_FILE_ATTRIBUTE_DATA *data, MonoIOStat *stat)
181 stat->attributes = data->dwFileAttributes;
182 stat->creation_time = convert_filetime (&data->ftCreationTime);
183 stat->last_access_time = convert_filetime (&data->ftLastAccessTime);
184 stat->last_write_time = convert_filetime (&data->ftLastWriteTime);
185 stat->length = ((gint64)data->nFileSizeHigh << 32) | data->nFileSizeLow;
188 /* Managed file attributes have nearly but not quite the same values
189 * as the w32 equivalents.
191 static guint32 convert_attrs(MonoFileAttributes attrs)
193 if(attrs & FileAttributes_Encrypted) {
194 attrs = (MonoFileAttributes)(attrs | FILE_ATTRIBUTE_ENCRYPTED);
201 * On Win32, GetFileAttributes|Ex () seems to try opening the file,
202 * which might lead to sharing violation errors, whereas FindFirstFile
203 * always succeeds. These 2 wrappers resort to FindFirstFile if
204 * GetFileAttributes|Ex () has failed.
207 get_file_attributes (const gunichar2 *path)
210 WIN32_FIND_DATA find_data;
214 res = GetFileAttributes (path);
218 error = GetLastError ();
220 if (error != ERROR_SHARING_VIOLATION)
223 find_handle = FindFirstFile (path, &find_data);
225 if (find_handle == INVALID_HANDLE_VALUE)
228 FindClose (find_handle);
230 return find_data.dwFileAttributes;
234 get_file_attributes_ex (const gunichar2 *path, WIN32_FILE_ATTRIBUTE_DATA *data)
237 WIN32_FIND_DATA find_data;
241 res = GetFileAttributesEx (path, GetFileExInfoStandard, data);
245 error = GetLastError ();
247 if (error != ERROR_SHARING_VIOLATION)
250 find_handle = FindFirstFile (path, &find_data);
252 if (find_handle == INVALID_HANDLE_VALUE)
255 FindClose (find_handle);
257 data->dwFileAttributes = find_data.dwFileAttributes;
258 data->ftCreationTime = find_data.ftCreationTime;
259 data->ftLastAccessTime = find_data.ftLastAccessTime;
260 data->ftLastWriteTime = find_data.ftLastWriteTime;
261 data->nFileSizeHigh = find_data.nFileSizeHigh;
262 data->nFileSizeLow = find_data.nFileSizeLow;
267 /* System.IO.MonoIO internal calls */
270 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 ();
287 ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error)
292 *error=ERROR_SUCCESS;
294 ret=RemoveDirectory (mono_string_chars (path));
296 *error=GetLastError ();
304 get_search_dir (const gunichar2 *pattern)
309 p = g_utf16_to_utf8 (pattern, -1, NULL, NULL, NULL);
310 result = g_path_get_dirname (p);
316 get_filesystem_entries (const gunichar2 *path,
317 const gunichar2 *path_with_pattern,
318 gint attrs, gint mask,
322 WIN32_FIND_DATA data;
324 GPtrArray *names = NULL;
325 gchar *utf8_path = NULL, *utf8_result, *full_name;
328 mask = convert_attrs ((MonoFileAttributes)mask);
329 attributes = get_file_attributes (path);
330 if (attributes != -1) {
331 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
332 *error = ERROR_INVALID_NAME;
336 *error = GetLastError ();
340 find_handle = FindFirstFile (path_with_pattern, &data);
341 if (find_handle == INVALID_HANDLE_VALUE) {
342 gint32 find_error = GetLastError ();
344 if (find_error == ERROR_FILE_NOT_FOUND || find_error == ERROR_NO_MORE_FILES) {
345 /* No files, so just return an empty array */
353 utf8_path = get_search_dir (path_with_pattern);
354 names = g_ptr_array_new ();
357 if ((data.cFileName[0] == '.' && data.cFileName[1] == 0) ||
358 (data.cFileName[0] == '.' && data.cFileName[1] == '.' && data.cFileName[2] == 0)) {
362 if ((data.dwFileAttributes & mask) == attrs) {
363 utf8_result = g_utf16_to_utf8 (data.cFileName, -1, NULL, NULL, NULL);
364 if (utf8_result == NULL) {
368 full_name = g_build_filename (utf8_path, utf8_result, NULL);
369 g_ptr_array_add (names, full_name);
371 g_free (utf8_result);
373 } while(FindNextFile (find_handle, &data));
375 if (FindClose (find_handle) == FALSE) {
376 *error = GetLastError ();
384 for (i = 0; i < names->len; i++)
385 g_free (g_ptr_array_index (names, i));
386 g_ptr_array_free (names, TRUE);
394 ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
395 MonoString *path_with_pattern,
396 gint attrs, gint mask,
400 MonoDomain *domain = mono_domain_get ();
405 *ioerror = ERROR_SUCCESS;
408 names = get_filesystem_entries (mono_string_chars (path), mono_string_chars (path_with_pattern), attrs, mask, ioerror);
412 // If there's no array and no error, then return an empty array.
413 if (*ioerror == ERROR_SUCCESS) {
414 MonoArray *arr = mono_array_new_checked (domain, mono_defaults.string_class, 0, &error);
415 mono_error_set_pending_exception (&error);
421 result = mono_array_new_checked (domain, mono_defaults.string_class, names->len, &error);
422 if (mono_error_set_pending_exception (&error))
424 for (i = 0; i < names->len; i++) {
425 mono_array_setref (result, i, mono_string_new (domain, (const char *)g_ptr_array_index (names, i)));
426 g_free (g_ptr_array_index (names, i));
429 g_ptr_array_free (names, TRUE);
440 incremental_find_check_match (IncrementalFind *handle, WIN32_FIND_DATA *data, MonoString **result)
445 if ((data->cFileName[0] == '.' && data->cFileName[1] == 0) || (data->cFileName[0] == '.' && data->cFileName[1] == '.' && data->cFileName[2] == 0))
448 utf8_result = g_utf16_to_utf8 (data->cFileName, -1, NULL, NULL, NULL);
449 if (utf8_result == NULL)
452 full_name = g_build_filename (handle->utf8_path, utf8_result, NULL);
453 g_free (utf8_result);
454 *result = mono_string_new (mono_domain_get (), full_name);
460 /* FIXME make gc suspendable */
462 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
463 MonoString *path_with_pattern,
464 gint32 *result_attr, gint32 *error,
467 WIN32_FIND_DATA data;
469 IncrementalFind *ifh;
472 *error = ERROR_SUCCESS;
474 find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data);
476 if (find_handle == INVALID_HANDLE_VALUE) {
477 gint32 find_error = GetLastError ();
480 if (find_error == ERROR_FILE_NOT_FOUND)
487 ifh = g_new (IncrementalFind, 1);
488 ifh->find_handle = find_handle;
489 ifh->utf8_path = mono_string_to_utf8 (path);
490 ifh->domain = mono_domain_get ();
493 while (incremental_find_check_match (ifh, &data, &result) == 0){
494 if (FindNextFile (find_handle, &data) == FALSE){
495 int e = GetLastError ();
496 if (e != ERROR_NO_MORE_FILES)
501 *result_attr = data.dwFileAttributes;
506 /* FIXME make gc suspendable */
508 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint32 *error)
510 IncrementalFind *ifh = (IncrementalFind *)handle;
511 WIN32_FIND_DATA data;
514 *error = ERROR_SUCCESS;
516 if (FindNextFile (ifh->find_handle, &data) == FALSE){
517 int e = GetLastError ();
518 if (e != ERROR_NO_MORE_FILES)
522 } while (incremental_find_check_match (ifh, &data, &result) == 0);
524 *result_attr = data.dwFileAttributes;
529 ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
531 IncrementalFind *ifh = (IncrementalFind *)handle;
535 if (FindClose (ifh->find_handle) == FALSE){
536 error = GetLastError ();
538 error = ERROR_SUCCESS;
539 g_free (ifh->utf8_path);
547 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *io_error)
554 len = MAX_PATH + 1; /*FIXME this is too smal under most unix systems.*/
555 buf = g_new (gunichar2, len);
557 mono_error_init (&error);
558 *io_error=ERROR_SUCCESS;
561 res_len = GetCurrentDirectory (len, buf);
562 if (res_len > len) { /*buf is too small.*/
563 int old_res_len = res_len;
565 buf = g_new (gunichar2, res_len);
566 res_len = GetCurrentDirectory (res_len, buf) == old_res_len;
574 result = mono_string_new_utf16_checked (mono_domain_get (), buf, len, &error);
576 *io_error=GetLastError ();
580 mono_error_set_pending_exception (&error);
585 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
590 *error=ERROR_SUCCESS;
592 ret=SetCurrentDirectory (mono_string_chars (path));
594 *error=GetLastError ();
601 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest,
607 *error=ERROR_SUCCESS;
609 ret=MoveFile (mono_string_chars (path), mono_string_chars (dest));
611 *error=GetLastError ();
619 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
620 MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
624 gunichar2 *utf16_sourceFileName = NULL, *utf16_destinationFileName = NULL, *utf16_destinationBackupFileName = NULL;
625 guint32 replaceFlags = REPLACEFILE_WRITE_THROUGH;
629 utf16_sourceFileName = mono_string_chars (sourceFileName);
630 if (destinationFileName)
631 utf16_destinationFileName = mono_string_chars (destinationFileName);
632 if (destinationBackupFileName)
633 utf16_destinationBackupFileName = mono_string_chars (destinationBackupFileName);
635 *error = ERROR_SUCCESS;
636 if (ignoreMetadataErrors)
637 replaceFlags |= REPLACEFILE_IGNORE_MERGE_ERRORS;
639 /* FIXME: source and destination file names must not be NULL, but apparently they might be! */
640 ret = ReplaceFile (utf16_destinationFileName, utf16_sourceFileName, utf16_destinationBackupFileName,
641 replaceFlags, NULL, NULL);
643 *error = GetLastError ();
650 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
651 MonoBoolean overwrite, gint32 *error)
656 *error=ERROR_SUCCESS;
658 ret=CopyFile (mono_string_chars (path), mono_string_chars (dest), !overwrite);
660 *error=GetLastError ();
668 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error)
673 *error=ERROR_SUCCESS;
675 ret=DeleteFile (mono_string_chars (path));
677 *error=GetLastError ();
685 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error)
690 *error=ERROR_SUCCESS;
692 ret=get_file_attributes (mono_string_chars (path));
695 * The definition of INVALID_FILE_ATTRIBUTES in the cygwin win32
696 * headers is wrong, hence this temporary workaround.
698 * http://cygwin.com/ml/cygwin/2003-09/msg01771.html
701 /* if(ret==INVALID_FILE_ATTRIBUTES) { */
702 *error=GetLastError ();
710 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
716 *error=ERROR_SUCCESS;
718 ret=SetFileAttributes (mono_string_chars (path),
719 convert_attrs ((MonoFileAttributes)attrs));
721 *error=GetLastError ();
729 ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error)
734 *error=ERROR_SUCCESS;
736 ret=GetFileType (handle);
737 if(ret==FILE_TYPE_UNKNOWN) {
738 /* Not necessarily an error, but the caller will have
739 * to decide based on the error value.
741 *error=GetLastError ();
749 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat,
753 WIN32_FILE_ATTRIBUTE_DATA data;
756 *error=ERROR_SUCCESS;
758 result = get_file_attributes_ex (mono_string_chars (path), &data);
761 convert_win32_file_attribute_data (&data, stat);
763 *error=GetLastError ();
764 memset (stat, 0, sizeof (MonoIOStat));
772 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
773 gint32 access_mode, gint32 share, gint32 options,
777 int attributes, attrs;
781 chars = mono_string_chars (filename);
782 *error=ERROR_SUCCESS;
785 if (options & FileOptions_Encrypted)
786 attributes = FILE_ATTRIBUTE_ENCRYPTED;
788 attributes = FILE_ATTRIBUTE_NORMAL;
789 if (options & FileOptions_DeleteOnClose)
790 attributes |= FILE_FLAG_DELETE_ON_CLOSE;
791 if (options & FileOptions_SequentialScan)
792 attributes |= FILE_FLAG_SEQUENTIAL_SCAN;
793 if (options & FileOptions_RandomAccess)
794 attributes |= FILE_FLAG_RANDOM_ACCESS;
796 if (options & FileOptions_Temporary)
797 attributes |= FILE_ATTRIBUTE_TEMPORARY;
799 /* Not sure if we should set FILE_FLAG_OVERLAPPED, how does this mix with the "Async" bool here? */
800 if (options & FileOptions_Asynchronous)
801 attributes |= FILE_FLAG_OVERLAPPED;
803 if (options & FileOptions_WriteThrough)
804 attributes |= FILE_FLAG_WRITE_THROUGH;
806 attributes = FILE_ATTRIBUTE_NORMAL;
808 /* If we're opening a directory we need to set the extra flag
810 attrs = get_file_attributes (chars);
811 if (attrs != INVALID_FILE_ATTRIBUTES) {
812 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
813 attributes |= FILE_FLAG_BACKUP_SEMANTICS;
817 ret=CreateFile (chars, convert_access ((MonoFileAccess)access_mode),
818 convert_share ((MonoFileShare)share), NULL, convert_mode ((MonoFileMode)mode),
820 if(ret==INVALID_HANDLE_VALUE) {
821 *error=GetLastError ();
829 ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error)
834 *error=ERROR_SUCCESS;
836 ret=CloseHandle (handle);
838 *error=GetLastError ();
846 ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
847 gint32 dest_offset, gint32 count,
854 *error=ERROR_SUCCESS;
856 MONO_CHECK_ARG_NULL (dest, 0);
858 if (dest_offset > mono_array_length (dest) - count) {
859 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
863 buffer = mono_array_addr (dest, guchar, dest_offset);
866 result = ReadFile (handle, buffer, count, &n, NULL);
870 *error=GetLastError ();
878 ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
879 gint32 src_offset, gint32 count,
886 *error=ERROR_SUCCESS;
888 MONO_CHECK_ARG_NULL (src, 0);
890 if (src_offset > mono_array_length (src) - count) {
891 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
895 buffer = mono_array_addr (src, guchar, src_offset);
897 result = WriteFile (handle, buffer, count, &n, NULL);
901 *error=GetLastError ();
909 ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
915 *error=ERROR_SUCCESS;
917 offset_hi = offset >> 32;
918 offset = SetFilePointer (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
919 convert_seekorigin ((MonoSeekOrigin)origin));
921 if(offset==INVALID_SET_FILE_POINTER) {
922 *error=GetLastError ();
926 return offset | ((gint64)offset_hi << 32);
930 ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error)
935 *error=ERROR_SUCCESS;
937 ret=FlushFileBuffers (handle);
939 *error=GetLastError ();
947 ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error)
953 *error=ERROR_SUCCESS;
955 length = GetFileSize (handle, &length_hi);
956 if(length==INVALID_FILE_SIZE) {
957 *error=GetLastError ();
961 return length | ((gint64)length_hi << 32);
964 /* FIXME make gc suspendable */
966 ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
969 gint64 offset, offset_set;
974 *error=ERROR_SUCCESS;
976 /* save file pointer */
979 offset = SetFilePointer (handle, 0, &offset_hi, FILE_CURRENT);
980 if(offset==INVALID_SET_FILE_POINTER) {
981 *error=GetLastError ();
985 /* extend or truncate */
987 length_hi = length >> 32;
988 offset_set=SetFilePointer (handle, length & 0xFFFFFFFF, &length_hi,
990 if(offset_set==INVALID_SET_FILE_POINTER) {
991 *error=GetLastError ();
995 result = SetEndOfFile (handle);
997 *error=GetLastError ();
1001 /* restore file pointer */
1003 offset_set=SetFilePointer (handle, offset & 0xFFFFFFFF, &offset_hi,
1005 if(offset_set==INVALID_SET_FILE_POINTER) {
1006 *error=GetLastError ();
1014 ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time,
1015 gint64 last_access_time,
1016 gint64 last_write_time, gint32 *error)
1019 const FILETIME *creation_filetime;
1020 const FILETIME *last_access_filetime;
1021 const FILETIME *last_write_filetime;
1024 *error=ERROR_SUCCESS;
1026 if (creation_time < 0)
1027 creation_filetime = NULL;
1029 creation_filetime = (FILETIME *)&creation_time;
1031 if (last_access_time < 0)
1032 last_access_filetime = NULL;
1034 last_access_filetime = (FILETIME *)&last_access_time;
1036 if (last_write_time < 0)
1037 last_write_filetime = NULL;
1039 last_write_filetime = (FILETIME *)&last_write_time;
1041 ret=SetFileTime (handle, creation_filetime, last_access_filetime, last_write_filetime);
1043 *error=GetLastError ();
1051 ves_icall_System_IO_MonoIO_get_ConsoleOutput ()
1053 return GetStdHandle (STD_OUTPUT_HANDLE);
1057 ves_icall_System_IO_MonoIO_get_ConsoleInput ()
1059 return GetStdHandle (STD_INPUT_HANDLE);
1063 ves_icall_System_IO_MonoIO_get_ConsoleError ()
1065 return GetStdHandle (STD_ERROR_HANDLE);
1069 ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle, HANDLE *write_handle, gint32 *error)
1071 SECURITY_ATTRIBUTES attr;
1074 attr.nLength=sizeof(SECURITY_ATTRIBUTES);
1075 attr.bInheritHandle=TRUE;
1076 attr.lpSecurityDescriptor=NULL;
1079 ret=CreatePipe (read_handle, write_handle, &attr, 0);
1083 *error = GetLastError ();
1084 /* FIXME: throw an exception? */
1092 ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle, HANDLE source_handle,
1093 HANDLE target_process_handle, HANDLE *target_handle, gint32 access, gint32 inherit, gint32 options, gint32 *error)
1095 /* This is only used on Windows */
1099 ret=DuplicateHandle (source_process_handle, source_handle, target_process_handle, target_handle, access, inherit, options);
1103 *error = GetLastError ();
1104 /* FIXME: throw an exception? */
1112 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
1114 #if defined (TARGET_WIN32)
1115 return (gunichar2) ':'; /* colon */
1117 return (gunichar2) '/'; /* forward slash */
1122 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
1124 #if defined (TARGET_WIN32)
1125 return (gunichar2) '\\'; /* backslash */
1127 return (gunichar2) '/'; /* forward slash */
1132 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
1134 #if defined (TARGET_WIN32)
1135 return (gunichar2) '/'; /* forward slash */
1137 if (IS_PORTABILITY_SET)
1138 return (gunichar2) '\\'; /* backslash */
1140 return (gunichar2) '/'; /* forward slash */
1145 ves_icall_System_IO_MonoIO_get_PathSeparator ()
1147 #if defined (TARGET_WIN32)
1148 return (gunichar2) ';'; /* semicolon */
1150 return (gunichar2) ':'; /* colon */
1154 static const gunichar2
1155 invalid_path_chars [] = {
1156 #if defined (TARGET_WIN32)
1157 0x0022, /* double quote, which seems allowed in MS.NET but should be rejected */
1158 0x003c, /* less than */
1159 0x003e, /* greater than */
1176 ves_icall_System_IO_MonoIO_get_InvalidPathChars ()
1183 domain = mono_domain_get ();
1184 n = sizeof (invalid_path_chars) / sizeof (gunichar2);
1185 chars = mono_array_new_checked (domain, mono_defaults.char_class, n, &error);
1186 if (mono_error_set_pending_exception (&error))
1189 for (i = 0; i < n; ++ i)
1190 mono_array_set (chars, gunichar2, i, invalid_path_chars [i]);
1195 void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position,
1196 gint64 length, gint32 *error)
1201 *error=ERROR_SUCCESS;
1203 ret=LockFile (handle, position & 0xFFFFFFFF, position >> 32,
1204 length & 0xFFFFFFFF, length >> 32);
1206 *error = GetLastError ();
1212 void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
1213 gint64 length, gint32 *error)
1218 *error=ERROR_SUCCESS;
1220 ret=UnlockFile (handle, position & 0xFFFFFFFF, position >> 32,
1221 length & 0xFFFFFFFF, length >> 32);
1223 *error = GetLastError ();
1229 //Support for io-layer free mmap'd files.
1231 #if defined (TARGET_IOS) || defined (TARGET_ANDROID)
1234 mono_filesize_from_path (MonoString *string)
1238 char *path = mono_string_to_utf8 (string);
1241 if (stat (path, &buf) == -1)
1244 res = (gint64)buf.st_size;
1253 mono_filesize_from_fd (int fd)
1259 res = fstat (fd, &buf);
1265 return (gint64)buf.st_size;
1270 void _wapi_handle_dump (void);
1272 void ves_icall_System_IO_MonoIO_DumpHandles (void)
1275 _wapi_handle_dump ();