2 * w32file.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/w32file.h>
32 #include <mono/metadata/w32file-internals.h>
33 #include <mono/metadata/exception.h>
34 #include <mono/metadata/appdomain.h>
35 #include <mono/metadata/marshal.h>
36 #include <mono/utils/strenc.h>
37 #include <utils/mono-io-portability.h>
38 #include <mono/metadata/w32handle.h>
42 /* conversion functions */
44 static guint32 convert_mode(MonoFileMode mono_mode)
49 case FileMode_CreateNew:
58 case FileMode_OpenOrCreate:
61 case FileMode_Truncate:
62 mode=TRUNCATE_EXISTING;
68 g_warning("System.IO.FileMode has unknown value 0x%x",
77 static guint32 convert_access(MonoFileAccess mono_access)
85 case FileAccess_Write:
88 case FileAccess_ReadWrite:
89 access=GENERIC_READ|GENERIC_WRITE;
92 g_warning("System.IO.FileAccess has unknown value 0x%x",
101 static guint32 convert_share(MonoFileShare mono_share)
105 if (mono_share & FileShare_Read) {
106 share |= FILE_SHARE_READ;
108 if (mono_share & FileShare_Write) {
109 share |= FILE_SHARE_WRITE;
111 if (mono_share & FileShare_Delete) {
112 share |= FILE_SHARE_DELETE;
115 if (mono_share & ~(FileShare_Read|FileShare_Write|FileShare_Delete)) {
116 g_warning("System.IO.FileShare has unknown value 0x%x",
126 static guint32 convert_stdhandle(guint32 fd)
132 stdhandle=STD_INPUT_HANDLE;
135 stdhandle=STD_OUTPUT_HANDLE;
138 stdhandle=STD_ERROR_HANDLE;
141 g_warning("unknown standard file descriptor %d", fd);
142 stdhandle=STD_INPUT_HANDLE;
149 static guint32 convert_seekorigin(MonoSeekOrigin origin)
154 case SeekOrigin_Begin:
155 w32origin=FILE_BEGIN;
157 case SeekOrigin_Current:
158 w32origin=FILE_CURRENT;
164 g_warning("System.IO.SeekOrigin has unknown value 0x%x",
167 w32origin=FILE_CURRENT;
173 static gint64 convert_filetime (const FILETIME *filetime)
175 return (gint64) ((((guint64) filetime->dwHighDateTime) << 32) + filetime->dwLowDateTime);
178 /* Managed file attributes have nearly but not quite the same values
179 * as the w32 equivalents.
181 static guint32 convert_attrs(MonoFileAttributes attrs)
183 if(attrs & FileAttributes_Encrypted) {
184 attrs = (MonoFileAttributes)(attrs | FILE_ATTRIBUTE_ENCRYPTED);
191 * On Win32, mono_w32file_get_attributes|_ex () seems to try opening the file,
192 * which might lead to sharing violation errors, whereas mono_w32file_find_first
193 * always succeeds. These 2 wrappers resort to mono_w32file_find_first if
194 * mono_w32file_get_attributes|_ex () has failed.
197 get_file_attributes (const gunichar2 *path)
200 WIN32_FIND_DATA find_data;
204 res = mono_w32file_get_attributes (path);
208 error = GetLastError ();
210 if (error != ERROR_SHARING_VIOLATION)
213 find_handle = mono_w32file_find_first (path, &find_data);
215 if (find_handle == INVALID_HANDLE_VALUE)
218 mono_w32file_find_close (find_handle);
220 return find_data.dwFileAttributes;
224 get_file_attributes_ex (const gunichar2 *path, MonoIOStat *stat)
227 WIN32_FIND_DATA find_data;
231 res = mono_w32file_get_attributes_ex (path, stat);
235 error = GetLastError ();
236 if (error != ERROR_SHARING_VIOLATION)
239 find_handle = mono_w32file_find_first (path, &find_data);
241 if (find_handle == INVALID_HANDLE_VALUE)
244 mono_w32file_find_close (find_handle);
246 stat->attributes = find_data.dwFileAttributes;
247 stat->creation_time = convert_filetime (&find_data.ftCreationTime);
248 stat->last_access_time = convert_filetime (&find_data.ftLastAccessTime);
249 stat->last_write_time = convert_filetime (&find_data.ftLastWriteTime);
250 stat->length = ((gint64)find_data.nFileSizeHigh << 32) | find_data.nFileSizeLow;
254 /* System.IO.MonoIO internal calls */
257 ves_icall_System_IO_MonoIO_CreateDirectory (MonoString *path, gint32 *error)
262 *error=ERROR_SUCCESS;
264 ret=mono_w32file_create_directory (mono_string_chars (path));
266 *error=GetLastError ();
274 ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error)
279 *error=ERROR_SUCCESS;
281 ret=mono_w32file_remove_directory (mono_string_chars (path));
283 *error=GetLastError ();
291 get_search_dir (const gunichar2 *pattern)
296 p = g_utf16_to_utf8 (pattern, -1, NULL, NULL, NULL);
297 result = g_path_get_dirname (p);
303 get_filesystem_entries (const gunichar2 *path,
304 const gunichar2 *path_with_pattern,
305 gint attrs, gint mask,
309 WIN32_FIND_DATA data;
311 GPtrArray *names = NULL;
312 gchar *utf8_path = NULL, *utf8_result, *full_name;
315 mask = convert_attrs ((MonoFileAttributes)mask);
316 attributes = get_file_attributes (path);
317 if (attributes != -1) {
318 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
319 *error = ERROR_INVALID_NAME;
323 *error = GetLastError ();
327 find_handle = mono_w32file_find_first (path_with_pattern, &data);
328 if (find_handle == INVALID_HANDLE_VALUE) {
329 gint32 find_error = GetLastError ();
331 if (find_error == ERROR_FILE_NOT_FOUND || find_error == ERROR_NO_MORE_FILES) {
332 /* No files, so just return an empty array */
340 utf8_path = get_search_dir (path_with_pattern);
341 names = g_ptr_array_new ();
344 if ((data.cFileName[0] == '.' && data.cFileName[1] == 0) ||
345 (data.cFileName[0] == '.' && data.cFileName[1] == '.' && data.cFileName[2] == 0)) {
349 if ((data.dwFileAttributes & mask) == attrs) {
350 utf8_result = g_utf16_to_utf8 (data.cFileName, -1, NULL, NULL, NULL);
351 if (utf8_result == NULL) {
355 full_name = g_build_filename (utf8_path, utf8_result, NULL);
356 g_ptr_array_add (names, full_name);
358 g_free (utf8_result);
360 } while(mono_w32file_find_next (find_handle, &data));
362 if (mono_w32file_find_close (find_handle) == FALSE) {
363 *error = GetLastError ();
371 for (i = 0; i < names->len; i++)
372 g_free (g_ptr_array_index (names, i));
373 g_ptr_array_free (names, TRUE);
381 ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
382 MonoString *path_with_pattern,
383 gint attrs, gint mask,
387 MonoDomain *domain = mono_domain_get ();
392 *ioerror = ERROR_SUCCESS;
395 names = get_filesystem_entries (mono_string_chars (path), mono_string_chars (path_with_pattern), attrs, mask, ioerror);
399 // If there's no array and no error, then return an empty array.
400 if (*ioerror == ERROR_SUCCESS) {
401 MonoArray *arr = mono_array_new_checked (domain, mono_defaults.string_class, 0, &error);
402 mono_error_set_pending_exception (&error);
408 result = mono_array_new_checked (domain, mono_defaults.string_class, names->len, &error);
409 if (mono_error_set_pending_exception (&error))
411 for (i = 0; i < names->len; i++) {
412 mono_array_setref (result, i, mono_string_new (domain, (const char *)g_ptr_array_index (names, i)));
413 g_free (g_ptr_array_index (names, i));
416 g_ptr_array_free (names, TRUE);
427 incremental_find_check_match (IncrementalFind *handle, WIN32_FIND_DATA *data, MonoString **result)
432 if ((data->cFileName[0] == '.' && data->cFileName[1] == 0) || (data->cFileName[0] == '.' && data->cFileName[1] == '.' && data->cFileName[2] == 0))
435 utf8_result = g_utf16_to_utf8 (data->cFileName, -1, NULL, NULL, NULL);
436 if (utf8_result == NULL)
439 full_name = g_build_filename (handle->utf8_path, utf8_result, NULL);
440 g_free (utf8_result);
441 *result = mono_string_new (mono_domain_get (), full_name);
448 ves_icall_System_IO_MonoIO_FindFirstFile (MonoString *path_with_pattern, MonoString **file_name, gint32 *file_attr, gint32 *ioerror)
451 WIN32_FIND_DATA data;
454 hnd = mono_w32file_find_first (mono_string_chars (path_with_pattern), &data);
456 if (hnd == INVALID_HANDLE_VALUE) {
459 *ioerror = GetLastError ();
463 mono_gc_wbarrier_generic_store (file_name, (MonoObject*) mono_string_from_utf16_checked (data.cFileName, &error));
464 mono_error_set_pending_exception (&error);
466 *file_attr = data.dwFileAttributes;
467 *ioerror = ERROR_SUCCESS;
473 ves_icall_System_IO_MonoIO_FindNextFile (HANDLE hnd, MonoString **file_name, gint32 *file_attr, gint32 *ioerror)
476 WIN32_FIND_DATA data;
479 res = mono_w32file_find_next (hnd, &data);
484 *ioerror = GetLastError ();
488 mono_gc_wbarrier_generic_store (file_name, (MonoObject*) mono_string_from_utf16_checked (data.cFileName, &error));
489 mono_error_set_pending_exception (&error);
491 *file_attr = data.dwFileAttributes;
492 *ioerror = ERROR_SUCCESS;
498 ves_icall_System_IO_MonoIO_FindCloseFile (HANDLE hnd)
500 return mono_w32file_find_close (hnd);
503 /* FIXME make gc suspendable */
505 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
506 MonoString *path_with_pattern,
507 gint32 *result_attr, gint32 *ioerror,
511 WIN32_FIND_DATA data;
513 IncrementalFind *ifh;
516 *ioerror = ERROR_SUCCESS;
518 find_handle = mono_w32file_find_first (mono_string_chars (path_with_pattern), &data);
520 if (find_handle == INVALID_HANDLE_VALUE) {
521 gint32 find_error = GetLastError ();
524 if (find_error == ERROR_FILE_NOT_FOUND)
527 *ioerror = find_error;
531 ifh = g_new (IncrementalFind, 1);
532 ifh->find_handle = find_handle;
533 ifh->utf8_path = mono_string_to_utf8_checked (path, &error);
534 if (mono_error_set_pending_exception (&error)) {
536 mono_w32file_find_close (find_handle);
541 ifh->domain = mono_domain_get ();
544 while (incremental_find_check_match (ifh, &data, &result) == 0){
545 if (mono_w32file_find_next (find_handle, &data) == FALSE){
546 int e = GetLastError ();
547 if (e != ERROR_NO_MORE_FILES)
552 *result_attr = data.dwFileAttributes;
557 /* FIXME make gc suspendable */
559 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint32 *error)
561 IncrementalFind *ifh = (IncrementalFind *)handle;
562 WIN32_FIND_DATA data;
565 *error = ERROR_SUCCESS;
567 if (mono_w32file_find_next (ifh->find_handle, &data) == FALSE){
568 int e = GetLastError ();
569 if (e != ERROR_NO_MORE_FILES)
573 } while (incremental_find_check_match (ifh, &data, &result) == 0);
575 *result_attr = data.dwFileAttributes;
580 ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
582 IncrementalFind *ifh = (IncrementalFind *)handle;
586 if (mono_w32file_find_close (ifh->find_handle) == FALSE){
587 error = GetLastError ();
589 error = ERROR_SUCCESS;
590 g_free (ifh->utf8_path);
598 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *io_error)
605 len = MAX_PATH + 1; /*FIXME this is too smal under most unix systems.*/
606 buf = g_new (gunichar2, len);
608 mono_error_init (&error);
609 *io_error=ERROR_SUCCESS;
612 res_len = mono_w32file_get_cwd (len, buf);
613 if (res_len > len) { /*buf is too small.*/
614 int old_res_len = res_len;
616 buf = g_new (gunichar2, res_len);
617 res_len = mono_w32file_get_cwd (res_len, buf) == old_res_len;
625 result = mono_string_new_utf16_checked (mono_domain_get (), buf, len, &error);
627 *io_error=GetLastError ();
631 mono_error_set_pending_exception (&error);
636 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
641 *error=ERROR_SUCCESS;
643 ret=mono_w32file_set_cwd (mono_string_chars (path));
645 *error=GetLastError ();
652 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest, gint32 *error)
654 *error=ERROR_SUCCESS;
655 return mono_w32file_move (mono_string_chars (path), mono_string_chars (dest), error);
659 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
660 MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
663 gunichar2 *utf16_sourceFileName = NULL, *utf16_destinationFileName = NULL, *utf16_destinationBackupFileName = NULL;
664 guint32 replaceFlags = REPLACEFILE_WRITE_THROUGH;
667 utf16_sourceFileName = mono_string_chars (sourceFileName);
668 if (destinationFileName)
669 utf16_destinationFileName = mono_string_chars (destinationFileName);
670 if (destinationBackupFileName)
671 utf16_destinationBackupFileName = mono_string_chars (destinationBackupFileName);
673 *error = ERROR_SUCCESS;
674 if (ignoreMetadataErrors)
675 replaceFlags |= REPLACEFILE_IGNORE_MERGE_ERRORS;
677 /* FIXME: source and destination file names must not be NULL, but apparently they might be! */
678 return mono_w32file_replace (utf16_destinationFileName, utf16_sourceFileName,
679 utf16_destinationBackupFileName, replaceFlags, error);
683 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
684 MonoBoolean overwrite, gint32 *error)
686 *error=ERROR_SUCCESS;
687 return mono_w32file_copy (mono_string_chars (path), mono_string_chars (dest), overwrite, error);
691 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error)
696 *error=ERROR_SUCCESS;
698 ret=mono_w32file_delete (mono_string_chars (path));
700 *error=GetLastError ();
708 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error)
713 *error=ERROR_SUCCESS;
715 ret=get_file_attributes (mono_string_chars (path));
718 * The definition of INVALID_FILE_ATTRIBUTES in the cygwin win32
719 * headers is wrong, hence this temporary workaround.
721 * http://cygwin.com/ml/cygwin/2003-09/msg01771.html
724 /* if(ret==INVALID_FILE_ATTRIBUTES) { */
725 *error=GetLastError ();
733 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
739 *error=ERROR_SUCCESS;
741 ret=mono_w32file_set_attributes (mono_string_chars (path),
742 convert_attrs ((MonoFileAttributes)attrs));
744 *error=GetLastError ();
752 ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error)
757 *error=ERROR_SUCCESS;
759 ret=mono_w32file_get_type (handle);
760 if(ret==FILE_TYPE_UNKNOWN) {
761 /* Not necessarily an error, but the caller will have
762 * to decide based on the error value.
764 *error=GetLastError ();
772 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat, gint32 *error)
777 *error=ERROR_SUCCESS;
779 result = get_file_attributes_ex (mono_string_chars (path), stat);
782 *error=GetLastError ();
783 memset (stat, 0, sizeof (MonoIOStat));
791 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
792 gint32 access_mode, gint32 share, gint32 options,
796 int attributes, attrs;
800 chars = mono_string_chars (filename);
801 *error=ERROR_SUCCESS;
804 if (options & FileOptions_Encrypted)
805 attributes = FILE_ATTRIBUTE_ENCRYPTED;
807 attributes = FILE_ATTRIBUTE_NORMAL;
808 if (options & FileOptions_DeleteOnClose)
809 attributes |= FILE_FLAG_DELETE_ON_CLOSE;
810 if (options & FileOptions_SequentialScan)
811 attributes |= FILE_FLAG_SEQUENTIAL_SCAN;
812 if (options & FileOptions_RandomAccess)
813 attributes |= FILE_FLAG_RANDOM_ACCESS;
815 if (options & FileOptions_Temporary)
816 attributes |= FILE_ATTRIBUTE_TEMPORARY;
818 if (options & FileOptions_WriteThrough)
819 attributes |= FILE_FLAG_WRITE_THROUGH;
821 attributes = FILE_ATTRIBUTE_NORMAL;
823 /* If we're opening a directory we need to set the extra flag
825 attrs = get_file_attributes (chars);
826 if (attrs != INVALID_FILE_ATTRIBUTES) {
827 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
828 attributes |= FILE_FLAG_BACKUP_SEMANTICS;
832 ret=mono_w32file_create (chars, convert_access ((MonoFileAccess)access_mode), convert_share ((MonoFileShare)share), convert_mode ((MonoFileMode)mode), attributes);
833 if(ret==INVALID_HANDLE_VALUE) {
834 *error=GetLastError ();
842 ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error)
847 *error=ERROR_SUCCESS;
849 ret=CloseHandle (handle);
851 *error=GetLastError ();
859 ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
860 gint32 dest_offset, gint32 count,
867 *error=ERROR_SUCCESS;
869 MONO_CHECK_ARG_NULL (dest, 0);
871 if (dest_offset > mono_array_length (dest) - count) {
872 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
876 buffer = mono_array_addr (dest, guchar, dest_offset);
879 result = mono_w32file_read (handle, buffer, count, &n);
883 *error=GetLastError ();
891 ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
892 gint32 src_offset, gint32 count,
899 *error=ERROR_SUCCESS;
901 MONO_CHECK_ARG_NULL (src, 0);
903 if (src_offset > mono_array_length (src) - count) {
904 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
908 buffer = mono_array_addr (src, guchar, src_offset);
910 result = mono_w32file_write (handle, buffer, count, &n);
914 *error=GetLastError ();
922 ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
928 *error=ERROR_SUCCESS;
930 offset_hi = offset >> 32;
931 offset = mono_w32file_seek (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
932 convert_seekorigin ((MonoSeekOrigin)origin));
934 if(offset==INVALID_SET_FILE_POINTER) {
935 *error=GetLastError ();
939 return offset | ((gint64)offset_hi << 32);
943 ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error)
948 *error=ERROR_SUCCESS;
950 ret=mono_w32file_flush (handle);
952 *error=GetLastError ();
960 ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error)
962 *error=ERROR_SUCCESS;
963 return mono_w32file_get_file_size (handle, error);
966 /* FIXME make gc suspendable */
968 ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
971 gint64 offset, offset_set;
976 *error=ERROR_SUCCESS;
978 /* save file pointer */
981 offset = mono_w32file_seek (handle, 0, &offset_hi, FILE_CURRENT);
982 if(offset==INVALID_SET_FILE_POINTER) {
983 *error=GetLastError ();
987 /* extend or truncate */
989 length_hi = length >> 32;
990 offset_set=mono_w32file_seek (handle, length & 0xFFFFFFFF, &length_hi,
992 if(offset_set==INVALID_SET_FILE_POINTER) {
993 *error=GetLastError ();
997 result = mono_w32file_truncate (handle);
999 *error=GetLastError ();
1003 /* restore file pointer */
1005 offset_set=mono_w32file_seek (handle, offset & 0xFFFFFFFF, &offset_hi,
1007 if(offset_set==INVALID_SET_FILE_POINTER) {
1008 *error=GetLastError ();
1016 ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time,
1017 gint64 last_access_time,
1018 gint64 last_write_time, gint32 *error)
1021 const FILETIME *creation_filetime;
1022 const FILETIME *access_filetime;
1023 const FILETIME *write_filetime;
1026 *error=ERROR_SUCCESS;
1028 if (creation_time < 0)
1029 creation_filetime = NULL;
1031 creation_filetime = (FILETIME *)&creation_time;
1033 if (last_access_time < 0)
1034 access_filetime = NULL;
1036 access_filetime = (FILETIME *)&last_access_time;
1038 if (last_write_time < 0)
1039 write_filetime = NULL;
1041 write_filetime = (FILETIME *)&last_write_time;
1043 ret=mono_w32file_set_times (handle, creation_filetime, access_filetime, write_filetime);
1045 *error=GetLastError ();
1053 ves_icall_System_IO_MonoIO_get_ConsoleOutput ()
1055 return mono_w32file_get_console_output ();
1059 ves_icall_System_IO_MonoIO_get_ConsoleInput ()
1061 return mono_w32file_get_console_input ();
1065 ves_icall_System_IO_MonoIO_get_ConsoleError ()
1067 return mono_w32file_get_console_error ();
1071 ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle, HANDLE *write_handle, gint32 *error)
1076 ret=mono_w32file_create_pipe (read_handle, write_handle, 0);
1080 *error = GetLastError ();
1081 /* FIXME: throw an exception? */
1089 ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle, HANDLE source_handle,
1090 HANDLE target_process_handle, HANDLE *target_handle, gint32 access, gint32 inherit, gint32 options, gint32 *error)
1092 /* This is only used on Windows */
1097 ret=DuplicateHandle (source_process_handle, source_handle, target_process_handle, target_handle, access, inherit, options);
1099 mono_w32handle_ref (source_handle);
1100 *target_handle = source_handle;
1106 *error = GetLastError ();
1107 /* FIXME: throw an exception? */
1116 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
1118 return (gunichar2) '/'; /* forward slash */
1122 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
1124 return (gunichar2) '/'; /* forward slash */
1128 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
1130 if (IS_PORTABILITY_SET)
1131 return (gunichar2) '\\'; /* backslash */
1133 return (gunichar2) '/'; /* forward slash */
1137 ves_icall_System_IO_MonoIO_get_PathSeparator ()
1139 return (gunichar2) ':'; /* colon */
1141 #endif /* !HOST_WIN32 */
1143 static const gunichar2
1144 invalid_path_chars [] = {
1145 #if defined (TARGET_WIN32)
1146 0x0022, /* double quote, which seems allowed in MS.NET but should be rejected */
1147 0x003c, /* less than */
1148 0x003e, /* greater than */
1165 ves_icall_System_IO_MonoIO_get_InvalidPathChars ()
1172 domain = mono_domain_get ();
1173 n = sizeof (invalid_path_chars) / sizeof (gunichar2);
1174 chars = mono_array_new_checked (domain, mono_defaults.char_class, n, &error);
1175 if (mono_error_set_pending_exception (&error))
1178 for (i = 0; i < n; ++ i)
1179 mono_array_set (chars, gunichar2, i, invalid_path_chars [i]);
1184 void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position,
1185 gint64 length, gint32 *error)
1187 *error=ERROR_SUCCESS;
1188 mono_w32file_lock (handle, position, length, error);
1191 void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
1192 gint64 length, gint32 *error)
1194 *error=ERROR_SUCCESS;
1195 mono_w32file_unlock (handle, position, length, error);
1198 //Support for io-layer free mmap'd files.
1200 #if defined (TARGET_IOS) || defined (TARGET_ANDROID)
1203 mono_filesize_from_path (MonoString *string)
1208 char *path = mono_string_to_utf8_checked (string, &error);
1209 mono_error_raise_exception (&error); /* OK to throw, external only without a good alternative */
1212 if (stat (path, &buf) == -1)
1215 res = (gint64)buf.st_size;
1224 mono_filesize_from_fd (int fd)
1230 res = fstat (fd, &buf);
1236 return (gint64)buf.st_size;
1242 void mono_w32handle_dump (void);
1244 void ves_icall_System_IO_MonoIO_DumpHandles (void)
1246 mono_w32handle_dump ();
1248 #endif /* !HOST_WIN32 */