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/metadata/w32file.h>
31 #include <mono/metadata/w32error.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>
39 #include <mono/utils/w32api.h>
43 /* conversion functions */
45 static guint32 convert_mode(MonoFileMode mono_mode)
50 case FileMode_CreateNew:
59 case FileMode_OpenOrCreate:
62 case FileMode_Truncate:
63 mode=TRUNCATE_EXISTING;
69 g_warning("System.IO.FileMode has unknown value 0x%x",
78 static guint32 convert_access(MonoFileAccess mono_access)
86 case FileAccess_Write:
89 case FileAccess_ReadWrite:
90 access=GENERIC_READ|GENERIC_WRITE;
93 g_warning("System.IO.FileAccess has unknown value 0x%x",
102 static guint32 convert_share(MonoFileShare mono_share)
106 if (mono_share & FileShare_Read) {
107 share |= FILE_SHARE_READ;
109 if (mono_share & FileShare_Write) {
110 share |= FILE_SHARE_WRITE;
112 if (mono_share & FileShare_Delete) {
113 share |= FILE_SHARE_DELETE;
116 if (mono_share & ~(FileShare_Read|FileShare_Write|FileShare_Delete)) {
117 g_warning("System.IO.FileShare has unknown value 0x%x",
127 static guint32 convert_stdhandle(guint32 fd)
133 stdhandle=STD_INPUT_HANDLE;
136 stdhandle=STD_OUTPUT_HANDLE;
139 stdhandle=STD_ERROR_HANDLE;
142 g_warning("unknown standard file descriptor %d", fd);
143 stdhandle=STD_INPUT_HANDLE;
150 static guint32 convert_seekorigin(MonoSeekOrigin origin)
155 case SeekOrigin_Begin:
156 w32origin=FILE_BEGIN;
158 case SeekOrigin_Current:
159 w32origin=FILE_CURRENT;
165 g_warning("System.IO.SeekOrigin has unknown value 0x%x",
168 w32origin=FILE_CURRENT;
174 static gint64 convert_filetime (const FILETIME *filetime)
176 return (gint64) ((((guint64) filetime->dwHighDateTime) << 32) + filetime->dwLowDateTime);
179 /* Managed file attributes have nearly but not quite the same values
180 * as the w32 equivalents.
182 static guint32 convert_attrs(MonoFileAttributes attrs)
184 if(attrs & FileAttributes_Encrypted) {
185 attrs = (MonoFileAttributes)(attrs | FILE_ATTRIBUTE_ENCRYPTED);
192 * On Win32, mono_w32file_get_attributes|_ex () seems to try opening the file,
193 * which might lead to sharing violation errors, whereas mono_w32file_find_first
194 * always succeeds. These 2 wrappers resort to mono_w32file_find_first if
195 * mono_w32file_get_attributes|_ex () has failed.
198 get_file_attributes (const gunichar2 *path)
201 WIN32_FIND_DATA find_data;
205 res = mono_w32file_get_attributes (path);
209 error = mono_w32error_get_last ();
211 if (error != ERROR_SHARING_VIOLATION)
214 find_handle = mono_w32file_find_first (path, &find_data);
216 if (find_handle == INVALID_HANDLE_VALUE)
219 mono_w32file_find_close (find_handle);
221 return find_data.dwFileAttributes;
225 get_file_attributes_ex (const gunichar2 *path, MonoIOStat *stat)
228 WIN32_FIND_DATA find_data;
232 res = mono_w32file_get_attributes_ex (path, stat);
236 error = mono_w32error_get_last ();
237 if (error != ERROR_SHARING_VIOLATION)
240 find_handle = mono_w32file_find_first (path, &find_data);
242 if (find_handle == INVALID_HANDLE_VALUE)
245 mono_w32file_find_close (find_handle);
247 stat->attributes = find_data.dwFileAttributes;
248 stat->creation_time = convert_filetime (&find_data.ftCreationTime);
249 stat->last_access_time = convert_filetime (&find_data.ftLastAccessTime);
250 stat->last_write_time = convert_filetime (&find_data.ftLastWriteTime);
251 stat->length = ((gint64)find_data.nFileSizeHigh << 32) | find_data.nFileSizeLow;
255 /* System.IO.MonoIO internal calls */
258 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=mono_w32error_get_last ();
273 ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error)
277 *error=ERROR_SUCCESS;
279 ret=mono_w32file_remove_directory (mono_string_chars (path));
281 *error=mono_w32error_get_last ();
288 get_search_dir (const gunichar2 *pattern)
293 p = g_utf16_to_utf8 (pattern, -1, NULL, NULL, NULL);
294 result = g_path_get_dirname (p);
300 get_filesystem_entries (const gunichar2 *path,
301 const gunichar2 *path_with_pattern,
302 gint attrs, gint mask,
306 WIN32_FIND_DATA data;
308 GPtrArray *names = NULL;
309 gchar *utf8_path = NULL, *utf8_result, *full_name;
312 mask = convert_attrs ((MonoFileAttributes)mask);
313 attributes = get_file_attributes (path);
314 if (attributes != -1) {
315 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
316 *error = ERROR_INVALID_NAME;
320 *error = mono_w32error_get_last ();
324 find_handle = mono_w32file_find_first (path_with_pattern, &data);
325 if (find_handle == INVALID_HANDLE_VALUE) {
326 gint32 find_error = mono_w32error_get_last ();
328 if (find_error == ERROR_FILE_NOT_FOUND || find_error == ERROR_NO_MORE_FILES) {
329 /* No files, so just return an empty array */
337 utf8_path = get_search_dir (path_with_pattern);
338 names = g_ptr_array_new ();
341 if ((data.cFileName[0] == '.' && data.cFileName[1] == 0) ||
342 (data.cFileName[0] == '.' && data.cFileName[1] == '.' && data.cFileName[2] == 0)) {
346 if ((data.dwFileAttributes & mask) == attrs) {
347 utf8_result = g_utf16_to_utf8 (data.cFileName, -1, NULL, NULL, NULL);
348 if (utf8_result == NULL) {
352 full_name = g_build_filename (utf8_path, utf8_result, NULL);
353 g_ptr_array_add (names, full_name);
355 g_free (utf8_result);
357 } while(mono_w32file_find_next (find_handle, &data));
359 if (mono_w32file_find_close (find_handle) == FALSE) {
360 *error = mono_w32error_get_last ();
368 for (i = 0; i < names->len; i++)
369 g_free (g_ptr_array_index (names, i));
370 g_ptr_array_free (names, TRUE);
378 ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
379 MonoString *path_with_pattern,
380 gint attrs, gint mask,
384 MonoDomain *domain = mono_domain_get ();
389 *ioerror = ERROR_SUCCESS;
391 names = get_filesystem_entries (mono_string_chars (path), mono_string_chars (path_with_pattern), attrs, mask, ioerror);
394 // If there's no array and no error, then return an empty array.
395 if (*ioerror == ERROR_SUCCESS) {
396 MonoArray *arr = mono_array_new_checked (domain, mono_defaults.string_class, 0, &error);
397 mono_error_set_pending_exception (&error);
403 result = mono_array_new_checked (domain, mono_defaults.string_class, names->len, &error);
404 if (mono_error_set_pending_exception (&error))
406 for (i = 0; i < names->len; i++) {
407 mono_array_setref (result, i, mono_string_new (domain, (const char *)g_ptr_array_index (names, i)));
408 g_free (g_ptr_array_index (names, i));
411 g_ptr_array_free (names, TRUE);
422 incremental_find_check_match (IncrementalFind *handle, WIN32_FIND_DATA *data, MonoString **result)
427 if ((data->cFileName[0] == '.' && data->cFileName[1] == 0) || (data->cFileName[0] == '.' && data->cFileName[1] == '.' && data->cFileName[2] == 0))
430 utf8_result = g_utf16_to_utf8 (data->cFileName, -1, NULL, NULL, NULL);
431 if (utf8_result == NULL)
434 full_name = g_build_filename (handle->utf8_path, utf8_result, NULL);
435 g_free (utf8_result);
436 *result = mono_string_new (mono_domain_get (), full_name);
443 ves_icall_System_IO_MonoIO_FindFirstFile (MonoString *path_with_pattern, MonoString **file_name, gint32 *file_attr, gint32 *ioerror)
446 WIN32_FIND_DATA data;
449 hnd = mono_w32file_find_first (mono_string_chars (path_with_pattern), &data);
451 if (hnd == INVALID_HANDLE_VALUE) {
454 *ioerror = mono_w32error_get_last ();
458 mono_gc_wbarrier_generic_store (file_name, (MonoObject*) mono_string_from_utf16_checked (data.cFileName, &error));
459 mono_error_set_pending_exception (&error);
461 *file_attr = data.dwFileAttributes;
462 *ioerror = ERROR_SUCCESS;
468 ves_icall_System_IO_MonoIO_FindNextFile (HANDLE hnd, MonoString **file_name, gint32 *file_attr, gint32 *ioerror)
471 WIN32_FIND_DATA data;
474 res = mono_w32file_find_next (hnd, &data);
479 *ioerror = mono_w32error_get_last ();
483 mono_gc_wbarrier_generic_store (file_name, (MonoObject*) mono_string_from_utf16_checked (data.cFileName, &error));
484 mono_error_set_pending_exception (&error);
486 *file_attr = data.dwFileAttributes;
487 *ioerror = ERROR_SUCCESS;
493 ves_icall_System_IO_MonoIO_FindCloseFile (HANDLE hnd)
495 return mono_w32file_find_close (hnd);
498 /* FIXME make gc suspendable */
500 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
501 MonoString *path_with_pattern,
502 gint32 *result_attr, gint32 *ioerror,
506 WIN32_FIND_DATA data;
508 IncrementalFind *ifh;
511 *ioerror = ERROR_SUCCESS;
513 find_handle = mono_w32file_find_first (mono_string_chars (path_with_pattern), &data);
515 if (find_handle == INVALID_HANDLE_VALUE) {
516 gint32 find_error = mono_w32error_get_last ();
519 if (find_error == ERROR_FILE_NOT_FOUND)
522 *ioerror = find_error;
526 ifh = g_new (IncrementalFind, 1);
527 ifh->find_handle = find_handle;
528 ifh->utf8_path = mono_string_to_utf8_checked (path, &error);
529 if (mono_error_set_pending_exception (&error)) {
530 mono_w32file_find_close (find_handle);
534 ifh->domain = mono_domain_get ();
537 while (incremental_find_check_match (ifh, &data, &result) == 0){
538 if (mono_w32file_find_next (find_handle, &data) == FALSE){
539 int e = mono_w32error_get_last ();
540 if (e != ERROR_NO_MORE_FILES)
545 *result_attr = data.dwFileAttributes;
550 /* FIXME make gc suspendable */
552 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint32 *error)
554 IncrementalFind *ifh = (IncrementalFind *)handle;
555 WIN32_FIND_DATA data;
558 *error = ERROR_SUCCESS;
560 if (mono_w32file_find_next (ifh->find_handle, &data) == FALSE){
561 int e = mono_w32error_get_last ();
562 if (e != ERROR_NO_MORE_FILES)
566 } while (incremental_find_check_match (ifh, &data, &result) == 0);
568 *result_attr = data.dwFileAttributes;
573 ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
575 IncrementalFind *ifh = (IncrementalFind *)handle;
578 if (mono_w32file_find_close (ifh->find_handle) == FALSE){
579 error = mono_w32error_get_last ();
581 error = ERROR_SUCCESS;
582 g_free (ifh->utf8_path);
589 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *io_error)
596 len = MAX_PATH + 1; /*FIXME this is too smal under most unix systems.*/
597 buf = g_new (gunichar2, len);
600 *io_error=ERROR_SUCCESS;
603 res_len = mono_w32file_get_cwd (len, buf);
604 if (res_len > len) { /*buf is too small.*/
605 int old_res_len = res_len;
607 buf = g_new (gunichar2, res_len);
608 res_len = mono_w32file_get_cwd (res_len, buf) == old_res_len;
616 result = mono_string_new_utf16_checked (mono_domain_get (), buf, len, &error);
618 *io_error=mono_w32error_get_last ();
622 mono_error_set_pending_exception (&error);
627 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
632 *error=ERROR_SUCCESS;
634 ret=mono_w32file_set_cwd (mono_string_chars (path));
636 *error=mono_w32error_get_last ();
643 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest, gint32 *error)
645 *error=ERROR_SUCCESS;
646 return mono_w32file_move (mono_string_chars (path), mono_string_chars (dest), error);
650 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
651 MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
654 gunichar2 *utf16_sourceFileName = NULL, *utf16_destinationFileName = NULL, *utf16_destinationBackupFileName = NULL;
655 guint32 replaceFlags = REPLACEFILE_WRITE_THROUGH;
658 utf16_sourceFileName = mono_string_chars (sourceFileName);
659 if (destinationFileName)
660 utf16_destinationFileName = mono_string_chars (destinationFileName);
661 if (destinationBackupFileName)
662 utf16_destinationBackupFileName = mono_string_chars (destinationBackupFileName);
664 *error = ERROR_SUCCESS;
665 if (ignoreMetadataErrors)
666 replaceFlags |= REPLACEFILE_IGNORE_MERGE_ERRORS;
668 /* FIXME: source and destination file names must not be NULL, but apparently they might be! */
669 return mono_w32file_replace (utf16_destinationFileName, utf16_sourceFileName,
670 utf16_destinationBackupFileName, replaceFlags, error);
674 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
675 MonoBoolean overwrite, gint32 *error)
677 *error=ERROR_SUCCESS;
678 return mono_w32file_copy (mono_string_chars (path), mono_string_chars (dest), overwrite, error);
682 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error)
686 *error=ERROR_SUCCESS;
688 ret=mono_w32file_delete (mono_string_chars (path));
690 *error=mono_w32error_get_last ();
697 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error)
700 *error=ERROR_SUCCESS;
702 ret=get_file_attributes (mono_string_chars (path));
705 * The definition of INVALID_FILE_ATTRIBUTES in the cygwin win32
706 * headers is wrong, hence this temporary workaround.
708 * http://cygwin.com/ml/cygwin/2003-09/msg01771.html
711 /* if(ret==INVALID_FILE_ATTRIBUTES) { */
712 *error=mono_w32error_get_last ();
718 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
722 *error=ERROR_SUCCESS;
724 ret=mono_w32file_set_attributes (mono_string_chars (path),
725 convert_attrs ((MonoFileAttributes)attrs));
727 *error=mono_w32error_get_last ();
733 ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error)
737 *error=ERROR_SUCCESS;
739 ret=mono_w32file_get_type (handle);
740 if(ret==FILE_TYPE_UNKNOWN) {
741 /* Not necessarily an error, but the caller will have
742 * to decide based on the error value.
744 *error=mono_w32error_get_last ();
751 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat, gint32 *error)
755 *error=ERROR_SUCCESS;
757 result = get_file_attributes_ex (mono_string_chars (path), stat);
760 *error=mono_w32error_get_last ();
761 memset (stat, 0, sizeof (MonoIOStat));
768 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
769 gint32 access_mode, gint32 share, gint32 options,
773 int attributes, attrs;
776 chars = mono_string_chars (filename);
777 *error=ERROR_SUCCESS;
780 if (options & FileOptions_Encrypted)
781 attributes = FILE_ATTRIBUTE_ENCRYPTED;
783 attributes = FILE_ATTRIBUTE_NORMAL;
784 if (options & FileOptions_DeleteOnClose)
785 attributes |= FILE_FLAG_DELETE_ON_CLOSE;
786 if (options & FileOptions_SequentialScan)
787 attributes |= FILE_FLAG_SEQUENTIAL_SCAN;
788 if (options & FileOptions_RandomAccess)
789 attributes |= FILE_FLAG_RANDOM_ACCESS;
791 if (options & FileOptions_Temporary)
792 attributes |= FILE_ATTRIBUTE_TEMPORARY;
794 if (options & FileOptions_WriteThrough)
795 attributes |= FILE_FLAG_WRITE_THROUGH;
797 attributes = FILE_ATTRIBUTE_NORMAL;
799 /* If we're opening a directory we need to set the extra flag
801 attrs = get_file_attributes (chars);
802 if (attrs != INVALID_FILE_ATTRIBUTES) {
803 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
804 attributes |= FILE_FLAG_BACKUP_SEMANTICS;
808 ret=mono_w32file_create (chars, convert_access ((MonoFileAccess)access_mode), convert_share ((MonoFileShare)share), convert_mode ((MonoFileMode)mode), attributes);
809 if(ret==INVALID_HANDLE_VALUE) {
810 *error=mono_w32error_get_last ();
817 ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error)
820 *error=ERROR_SUCCESS;
822 ret=mono_w32file_close (handle);
824 *error=mono_w32error_get_last ();
830 ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
831 gint32 dest_offset, gint32 count,
838 *error=ERROR_SUCCESS;
840 MONO_CHECK_ARG_NULL (dest, 0);
842 if (dest_offset > mono_array_length (dest) - count) {
843 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
847 buffer = mono_array_addr (dest, guchar, dest_offset);
849 result = mono_w32file_read (handle, buffer, count, &n);
852 *error=mono_w32error_get_last ();
860 ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
861 gint32 src_offset, gint32 count,
868 *error=ERROR_SUCCESS;
870 MONO_CHECK_ARG_NULL (src, 0);
872 if (src_offset > mono_array_length (src) - count) {
873 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
877 buffer = mono_array_addr (src, guchar, src_offset);
878 result = mono_w32file_write (handle, buffer, count, &n);
881 *error=mono_w32error_get_last ();
889 ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
894 *error=ERROR_SUCCESS;
896 offset_hi = offset >> 32;
897 offset = mono_w32file_seek (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
898 convert_seekorigin ((MonoSeekOrigin)origin));
900 if(offset==INVALID_SET_FILE_POINTER) {
901 *error=mono_w32error_get_last ();
904 return offset | ((gint64)offset_hi << 32);
908 ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error)
912 *error=ERROR_SUCCESS;
914 ret=mono_w32file_flush (handle);
916 *error=mono_w32error_get_last ();
923 ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error)
925 *error=ERROR_SUCCESS;
926 return mono_w32file_get_file_size (handle, error);
929 /* FIXME make gc suspendable */
931 ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
934 gint64 offset, offset_set;
939 *error=ERROR_SUCCESS;
941 /* save file pointer */
944 offset = mono_w32file_seek (handle, 0, &offset_hi, FILE_CURRENT);
945 if(offset==INVALID_SET_FILE_POINTER) {
946 *error=mono_w32error_get_last ();
950 /* extend or truncate */
952 length_hi = length >> 32;
953 offset_set=mono_w32file_seek (handle, length & 0xFFFFFFFF, &length_hi,
955 if(offset_set==INVALID_SET_FILE_POINTER) {
956 *error=mono_w32error_get_last ();
960 result = mono_w32file_truncate (handle);
962 *error=mono_w32error_get_last ();
966 /* restore file pointer */
968 offset_set=mono_w32file_seek (handle, offset & 0xFFFFFFFF, &offset_hi,
970 if(offset_set==INVALID_SET_FILE_POINTER) {
971 *error=mono_w32error_get_last ();
979 ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time,
980 gint64 last_access_time,
981 gint64 last_write_time, gint32 *error)
984 const FILETIME *creation_filetime;
985 const FILETIME *access_filetime;
986 const FILETIME *write_filetime;
988 *error=ERROR_SUCCESS;
990 if (creation_time < 0)
991 creation_filetime = NULL;
993 creation_filetime = (FILETIME *)&creation_time;
995 if (last_access_time < 0)
996 access_filetime = NULL;
998 access_filetime = (FILETIME *)&last_access_time;
1000 if (last_write_time < 0)
1001 write_filetime = NULL;
1003 write_filetime = (FILETIME *)&last_write_time;
1005 ret=mono_w32file_set_times (handle, creation_filetime, access_filetime, write_filetime);
1007 *error=mono_w32error_get_last ();
1014 ves_icall_System_IO_MonoIO_get_ConsoleOutput ()
1016 return mono_w32file_get_console_output ();
1020 ves_icall_System_IO_MonoIO_get_ConsoleInput ()
1022 return mono_w32file_get_console_input ();
1026 ves_icall_System_IO_MonoIO_get_ConsoleError ()
1028 return mono_w32file_get_console_error ();
1032 ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle, HANDLE *write_handle, gint32 *error)
1036 ret=mono_w32file_create_pipe (read_handle, write_handle, 0);
1039 *error = mono_w32error_get_last ();
1040 /* FIXME: throw an exception? */
1048 ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle, HANDLE source_handle,
1049 HANDLE target_process_handle, HANDLE *target_handle, gint32 access, gint32 inherit, gint32 options, gint32 *error)
1051 /* This is only used on Windows */
1056 ret=DuplicateHandle (source_process_handle, source_handle, target_process_handle, target_handle, access, inherit, options);
1059 mono_w32handle_ref (source_handle);
1060 *target_handle = source_handle;
1065 *error = mono_w32error_get_last ();
1066 /* FIXME: throw an exception? */
1075 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
1077 return (gunichar2) '/'; /* forward slash */
1081 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
1083 return (gunichar2) '/'; /* forward slash */
1087 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
1089 if (IS_PORTABILITY_SET)
1090 return (gunichar2) '\\'; /* backslash */
1092 return (gunichar2) '/'; /* forward slash */
1096 ves_icall_System_IO_MonoIO_get_PathSeparator ()
1098 return (gunichar2) ':'; /* colon */
1100 #endif /* !HOST_WIN32 */
1102 static const gunichar2
1103 invalid_path_chars [] = {
1104 #if defined (TARGET_WIN32)
1105 0x0022, /* double quote, which seems allowed in MS.NET but should be rejected */
1106 0x003c, /* less than */
1107 0x003e, /* greater than */
1124 ves_icall_System_IO_MonoIO_get_InvalidPathChars ()
1131 domain = mono_domain_get ();
1132 n = sizeof (invalid_path_chars) / sizeof (gunichar2);
1133 chars = mono_array_new_checked (domain, mono_defaults.char_class, n, &error);
1134 if (mono_error_set_pending_exception (&error))
1137 for (i = 0; i < n; ++ i)
1138 mono_array_set (chars, gunichar2, i, invalid_path_chars [i]);
1143 void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position,
1144 gint64 length, gint32 *error)
1146 *error=ERROR_SUCCESS;
1147 mono_w32file_lock (handle, position, length, error);
1150 void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
1151 gint64 length, gint32 *error)
1153 *error=ERROR_SUCCESS;
1154 mono_w32file_unlock (handle, position, length, error);
1157 //Support for io-layer free mmap'd files.
1159 #if defined (TARGET_IOS) || defined (TARGET_ANDROID)
1162 mono_filesize_from_path (MonoString *string)
1167 char *path = mono_string_to_utf8_checked (string, &error);
1168 mono_error_raise_exception (&error); /* OK to throw, external only without a good alternative */
1172 stat_res = stat (path, &buf);
1177 res = (gint64)buf.st_size;
1185 mono_filesize_from_fd (int fd)
1191 res = fstat (fd, &buf);
1197 return (gint64)buf.st_size;
1203 void mono_w32handle_dump (void);
1205 void ves_icall_System_IO_MonoIO_DumpHandles (void)
1207 mono_w32handle_dump ();
1209 #endif /* !HOST_WIN32 */