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)
263 *error=ERROR_SUCCESS;
265 ret=mono_w32file_create_directory (mono_string_chars (path));
267 *error=mono_w32error_get_last ();
275 ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error)
280 *error=ERROR_SUCCESS;
282 ret=mono_w32file_remove_directory (mono_string_chars (path));
284 *error=mono_w32error_get_last ();
292 get_search_dir (const gunichar2 *pattern)
297 p = g_utf16_to_utf8 (pattern, -1, NULL, NULL, NULL);
298 result = g_path_get_dirname (p);
304 get_filesystem_entries (const gunichar2 *path,
305 const gunichar2 *path_with_pattern,
306 gint attrs, gint mask,
310 WIN32_FIND_DATA data;
312 GPtrArray *names = NULL;
313 gchar *utf8_path = NULL, *utf8_result, *full_name;
316 mask = convert_attrs ((MonoFileAttributes)mask);
317 attributes = get_file_attributes (path);
318 if (attributes != -1) {
319 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
320 *error = ERROR_INVALID_NAME;
324 *error = mono_w32error_get_last ();
328 find_handle = mono_w32file_find_first (path_with_pattern, &data);
329 if (find_handle == INVALID_HANDLE_VALUE) {
330 gint32 find_error = mono_w32error_get_last ();
332 if (find_error == ERROR_FILE_NOT_FOUND || find_error == ERROR_NO_MORE_FILES) {
333 /* No files, so just return an empty array */
341 utf8_path = get_search_dir (path_with_pattern);
342 names = g_ptr_array_new ();
345 if ((data.cFileName[0] == '.' && data.cFileName[1] == 0) ||
346 (data.cFileName[0] == '.' && data.cFileName[1] == '.' && data.cFileName[2] == 0)) {
350 if ((data.dwFileAttributes & mask) == attrs) {
351 utf8_result = g_utf16_to_utf8 (data.cFileName, -1, NULL, NULL, NULL);
352 if (utf8_result == NULL) {
356 full_name = g_build_filename (utf8_path, utf8_result, NULL);
357 g_ptr_array_add (names, full_name);
359 g_free (utf8_result);
361 } while(mono_w32file_find_next (find_handle, &data));
363 if (mono_w32file_find_close (find_handle) == FALSE) {
364 *error = mono_w32error_get_last ();
372 for (i = 0; i < names->len; i++)
373 g_free (g_ptr_array_index (names, i));
374 g_ptr_array_free (names, TRUE);
382 ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
383 MonoString *path_with_pattern,
384 gint attrs, gint mask,
388 MonoDomain *domain = mono_domain_get ();
393 *ioerror = ERROR_SUCCESS;
396 names = get_filesystem_entries (mono_string_chars (path), mono_string_chars (path_with_pattern), attrs, mask, ioerror);
400 // If there's no array and no error, then return an empty array.
401 if (*ioerror == ERROR_SUCCESS) {
402 MonoArray *arr = mono_array_new_checked (domain, mono_defaults.string_class, 0, &error);
403 mono_error_set_pending_exception (&error);
409 result = mono_array_new_checked (domain, mono_defaults.string_class, names->len, &error);
410 if (mono_error_set_pending_exception (&error))
412 for (i = 0; i < names->len; i++) {
413 mono_array_setref (result, i, mono_string_new (domain, (const char *)g_ptr_array_index (names, i)));
414 g_free (g_ptr_array_index (names, i));
417 g_ptr_array_free (names, TRUE);
428 incremental_find_check_match (IncrementalFind *handle, WIN32_FIND_DATA *data, MonoString **result)
433 if ((data->cFileName[0] == '.' && data->cFileName[1] == 0) || (data->cFileName[0] == '.' && data->cFileName[1] == '.' && data->cFileName[2] == 0))
436 utf8_result = g_utf16_to_utf8 (data->cFileName, -1, NULL, NULL, NULL);
437 if (utf8_result == NULL)
440 full_name = g_build_filename (handle->utf8_path, utf8_result, NULL);
441 g_free (utf8_result);
442 *result = mono_string_new (mono_domain_get (), full_name);
449 ves_icall_System_IO_MonoIO_FindFirstFile (MonoString *path_with_pattern, MonoString **file_name, gint32 *file_attr, gint32 *ioerror)
452 WIN32_FIND_DATA data;
455 hnd = mono_w32file_find_first (mono_string_chars (path_with_pattern), &data);
457 if (hnd == INVALID_HANDLE_VALUE) {
460 *ioerror = mono_w32error_get_last ();
464 mono_gc_wbarrier_generic_store (file_name, (MonoObject*) mono_string_from_utf16_checked (data.cFileName, &error));
465 mono_error_set_pending_exception (&error);
467 *file_attr = data.dwFileAttributes;
468 *ioerror = ERROR_SUCCESS;
474 ves_icall_System_IO_MonoIO_FindNextFile (HANDLE hnd, MonoString **file_name, gint32 *file_attr, gint32 *ioerror)
477 WIN32_FIND_DATA data;
480 res = mono_w32file_find_next (hnd, &data);
485 *ioerror = mono_w32error_get_last ();
489 mono_gc_wbarrier_generic_store (file_name, (MonoObject*) mono_string_from_utf16_checked (data.cFileName, &error));
490 mono_error_set_pending_exception (&error);
492 *file_attr = data.dwFileAttributes;
493 *ioerror = ERROR_SUCCESS;
499 ves_icall_System_IO_MonoIO_FindCloseFile (HANDLE hnd)
501 return mono_w32file_find_close (hnd);
504 /* FIXME make gc suspendable */
506 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
507 MonoString *path_with_pattern,
508 gint32 *result_attr, gint32 *ioerror,
512 WIN32_FIND_DATA data;
514 IncrementalFind *ifh;
517 *ioerror = ERROR_SUCCESS;
519 find_handle = mono_w32file_find_first (mono_string_chars (path_with_pattern), &data);
521 if (find_handle == INVALID_HANDLE_VALUE) {
522 gint32 find_error = mono_w32error_get_last ();
525 if (find_error == ERROR_FILE_NOT_FOUND)
528 *ioerror = find_error;
532 ifh = g_new (IncrementalFind, 1);
533 ifh->find_handle = find_handle;
534 ifh->utf8_path = mono_string_to_utf8_checked (path, &error);
535 if (mono_error_set_pending_exception (&error)) {
537 mono_w32file_find_close (find_handle);
542 ifh->domain = mono_domain_get ();
545 while (incremental_find_check_match (ifh, &data, &result) == 0){
546 if (mono_w32file_find_next (find_handle, &data) == FALSE){
547 int e = mono_w32error_get_last ();
548 if (e != ERROR_NO_MORE_FILES)
553 *result_attr = data.dwFileAttributes;
558 /* FIXME make gc suspendable */
560 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint32 *error)
562 IncrementalFind *ifh = (IncrementalFind *)handle;
563 WIN32_FIND_DATA data;
566 *error = ERROR_SUCCESS;
568 if (mono_w32file_find_next (ifh->find_handle, &data) == FALSE){
569 int e = mono_w32error_get_last ();
570 if (e != ERROR_NO_MORE_FILES)
574 } while (incremental_find_check_match (ifh, &data, &result) == 0);
576 *result_attr = data.dwFileAttributes;
581 ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
583 IncrementalFind *ifh = (IncrementalFind *)handle;
587 if (mono_w32file_find_close (ifh->find_handle) == FALSE){
588 error = mono_w32error_get_last ();
590 error = ERROR_SUCCESS;
591 g_free (ifh->utf8_path);
599 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *io_error)
606 len = MAX_PATH + 1; /*FIXME this is too smal under most unix systems.*/
607 buf = g_new (gunichar2, len);
609 mono_error_init (&error);
610 *io_error=ERROR_SUCCESS;
613 res_len = mono_w32file_get_cwd (len, buf);
614 if (res_len > len) { /*buf is too small.*/
615 int old_res_len = res_len;
617 buf = g_new (gunichar2, res_len);
618 res_len = mono_w32file_get_cwd (res_len, buf) == old_res_len;
626 result = mono_string_new_utf16_checked (mono_domain_get (), buf, len, &error);
628 *io_error=mono_w32error_get_last ();
632 mono_error_set_pending_exception (&error);
637 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
642 *error=ERROR_SUCCESS;
644 ret=mono_w32file_set_cwd (mono_string_chars (path));
646 *error=mono_w32error_get_last ();
653 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest, gint32 *error)
655 *error=ERROR_SUCCESS;
656 return mono_w32file_move (mono_string_chars (path), mono_string_chars (dest), error);
660 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
661 MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
664 gunichar2 *utf16_sourceFileName = NULL, *utf16_destinationFileName = NULL, *utf16_destinationBackupFileName = NULL;
665 guint32 replaceFlags = REPLACEFILE_WRITE_THROUGH;
668 utf16_sourceFileName = mono_string_chars (sourceFileName);
669 if (destinationFileName)
670 utf16_destinationFileName = mono_string_chars (destinationFileName);
671 if (destinationBackupFileName)
672 utf16_destinationBackupFileName = mono_string_chars (destinationBackupFileName);
674 *error = ERROR_SUCCESS;
675 if (ignoreMetadataErrors)
676 replaceFlags |= REPLACEFILE_IGNORE_MERGE_ERRORS;
678 /* FIXME: source and destination file names must not be NULL, but apparently they might be! */
679 return mono_w32file_replace (utf16_destinationFileName, utf16_sourceFileName,
680 utf16_destinationBackupFileName, replaceFlags, error);
684 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
685 MonoBoolean overwrite, gint32 *error)
687 *error=ERROR_SUCCESS;
688 return mono_w32file_copy (mono_string_chars (path), mono_string_chars (dest), overwrite, error);
692 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error)
697 *error=ERROR_SUCCESS;
699 ret=mono_w32file_delete (mono_string_chars (path));
701 *error=mono_w32error_get_last ();
709 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error)
714 *error=ERROR_SUCCESS;
716 ret=get_file_attributes (mono_string_chars (path));
719 * The definition of INVALID_FILE_ATTRIBUTES in the cygwin win32
720 * headers is wrong, hence this temporary workaround.
722 * http://cygwin.com/ml/cygwin/2003-09/msg01771.html
725 /* if(ret==INVALID_FILE_ATTRIBUTES) { */
726 *error=mono_w32error_get_last ();
734 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
740 *error=ERROR_SUCCESS;
742 ret=mono_w32file_set_attributes (mono_string_chars (path),
743 convert_attrs ((MonoFileAttributes)attrs));
745 *error=mono_w32error_get_last ();
753 ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error)
758 *error=ERROR_SUCCESS;
760 ret=mono_w32file_get_type (handle);
761 if(ret==FILE_TYPE_UNKNOWN) {
762 /* Not necessarily an error, but the caller will have
763 * to decide based on the error value.
765 *error=mono_w32error_get_last ();
773 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat, gint32 *error)
778 *error=ERROR_SUCCESS;
780 result = get_file_attributes_ex (mono_string_chars (path), stat);
783 *error=mono_w32error_get_last ();
784 memset (stat, 0, sizeof (MonoIOStat));
792 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
793 gint32 access_mode, gint32 share, gint32 options,
797 int attributes, attrs;
801 chars = mono_string_chars (filename);
802 *error=ERROR_SUCCESS;
805 if (options & FileOptions_Encrypted)
806 attributes = FILE_ATTRIBUTE_ENCRYPTED;
808 attributes = FILE_ATTRIBUTE_NORMAL;
809 if (options & FileOptions_DeleteOnClose)
810 attributes |= FILE_FLAG_DELETE_ON_CLOSE;
811 if (options & FileOptions_SequentialScan)
812 attributes |= FILE_FLAG_SEQUENTIAL_SCAN;
813 if (options & FileOptions_RandomAccess)
814 attributes |= FILE_FLAG_RANDOM_ACCESS;
816 if (options & FileOptions_Temporary)
817 attributes |= FILE_ATTRIBUTE_TEMPORARY;
819 if (options & FileOptions_WriteThrough)
820 attributes |= FILE_FLAG_WRITE_THROUGH;
822 attributes = FILE_ATTRIBUTE_NORMAL;
824 /* If we're opening a directory we need to set the extra flag
826 attrs = get_file_attributes (chars);
827 if (attrs != INVALID_FILE_ATTRIBUTES) {
828 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
829 attributes |= FILE_FLAG_BACKUP_SEMANTICS;
833 ret=mono_w32file_create (chars, convert_access ((MonoFileAccess)access_mode), convert_share ((MonoFileShare)share), convert_mode ((MonoFileMode)mode), attributes);
834 if(ret==INVALID_HANDLE_VALUE) {
835 *error=mono_w32error_get_last ();
843 ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error)
848 *error=ERROR_SUCCESS;
850 ret=mono_w32file_close (handle);
852 *error=mono_w32error_get_last ();
860 ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
861 gint32 dest_offset, gint32 count,
868 *error=ERROR_SUCCESS;
870 MONO_CHECK_ARG_NULL (dest, 0);
872 if (dest_offset > mono_array_length (dest) - count) {
873 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
877 buffer = mono_array_addr (dest, guchar, dest_offset);
880 result = mono_w32file_read (handle, buffer, count, &n);
884 *error=mono_w32error_get_last ();
892 ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
893 gint32 src_offset, gint32 count,
900 *error=ERROR_SUCCESS;
902 MONO_CHECK_ARG_NULL (src, 0);
904 if (src_offset > mono_array_length (src) - count) {
905 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
909 buffer = mono_array_addr (src, guchar, src_offset);
911 result = mono_w32file_write (handle, buffer, count, &n);
915 *error=mono_w32error_get_last ();
923 ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
929 *error=ERROR_SUCCESS;
931 offset_hi = offset >> 32;
932 offset = mono_w32file_seek (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
933 convert_seekorigin ((MonoSeekOrigin)origin));
935 if(offset==INVALID_SET_FILE_POINTER) {
936 *error=mono_w32error_get_last ();
940 return offset | ((gint64)offset_hi << 32);
944 ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error)
949 *error=ERROR_SUCCESS;
951 ret=mono_w32file_flush (handle);
953 *error=mono_w32error_get_last ();
961 ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error)
963 *error=ERROR_SUCCESS;
964 return mono_w32file_get_file_size (handle, error);
967 /* FIXME make gc suspendable */
969 ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
972 gint64 offset, offset_set;
977 *error=ERROR_SUCCESS;
979 /* save file pointer */
982 offset = mono_w32file_seek (handle, 0, &offset_hi, FILE_CURRENT);
983 if(offset==INVALID_SET_FILE_POINTER) {
984 *error=mono_w32error_get_last ();
988 /* extend or truncate */
990 length_hi = length >> 32;
991 offset_set=mono_w32file_seek (handle, length & 0xFFFFFFFF, &length_hi,
993 if(offset_set==INVALID_SET_FILE_POINTER) {
994 *error=mono_w32error_get_last ();
998 result = mono_w32file_truncate (handle);
1000 *error=mono_w32error_get_last ();
1004 /* restore file pointer */
1006 offset_set=mono_w32file_seek (handle, offset & 0xFFFFFFFF, &offset_hi,
1008 if(offset_set==INVALID_SET_FILE_POINTER) {
1009 *error=mono_w32error_get_last ();
1017 ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time,
1018 gint64 last_access_time,
1019 gint64 last_write_time, gint32 *error)
1022 const FILETIME *creation_filetime;
1023 const FILETIME *access_filetime;
1024 const FILETIME *write_filetime;
1027 *error=ERROR_SUCCESS;
1029 if (creation_time < 0)
1030 creation_filetime = NULL;
1032 creation_filetime = (FILETIME *)&creation_time;
1034 if (last_access_time < 0)
1035 access_filetime = NULL;
1037 access_filetime = (FILETIME *)&last_access_time;
1039 if (last_write_time < 0)
1040 write_filetime = NULL;
1042 write_filetime = (FILETIME *)&last_write_time;
1044 ret=mono_w32file_set_times (handle, creation_filetime, access_filetime, write_filetime);
1046 *error=mono_w32error_get_last ();
1054 ves_icall_System_IO_MonoIO_get_ConsoleOutput ()
1056 return mono_w32file_get_console_output ();
1060 ves_icall_System_IO_MonoIO_get_ConsoleInput ()
1062 return mono_w32file_get_console_input ();
1066 ves_icall_System_IO_MonoIO_get_ConsoleError ()
1068 return mono_w32file_get_console_error ();
1072 ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle, HANDLE *write_handle, gint32 *error)
1077 ret=mono_w32file_create_pipe (read_handle, write_handle, 0);
1081 *error = mono_w32error_get_last ();
1082 /* FIXME: throw an exception? */
1090 ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle, HANDLE source_handle,
1091 HANDLE target_process_handle, HANDLE *target_handle, gint32 access, gint32 inherit, gint32 options, gint32 *error)
1093 /* This is only used on Windows */
1098 ret=DuplicateHandle (source_process_handle, source_handle, target_process_handle, target_handle, access, inherit, options);
1100 mono_w32handle_ref (source_handle);
1101 *target_handle = source_handle;
1107 *error = mono_w32error_get_last ();
1108 /* FIXME: throw an exception? */
1117 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
1119 return (gunichar2) '/'; /* forward slash */
1123 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
1125 return (gunichar2) '/'; /* forward slash */
1129 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
1131 if (IS_PORTABILITY_SET)
1132 return (gunichar2) '\\'; /* backslash */
1134 return (gunichar2) '/'; /* forward slash */
1138 ves_icall_System_IO_MonoIO_get_PathSeparator ()
1140 return (gunichar2) ':'; /* colon */
1142 #endif /* !HOST_WIN32 */
1144 static const gunichar2
1145 invalid_path_chars [] = {
1146 #if defined (TARGET_WIN32)
1147 0x0022, /* double quote, which seems allowed in MS.NET but should be rejected */
1148 0x003c, /* less than */
1149 0x003e, /* greater than */
1166 ves_icall_System_IO_MonoIO_get_InvalidPathChars ()
1173 domain = mono_domain_get ();
1174 n = sizeof (invalid_path_chars) / sizeof (gunichar2);
1175 chars = mono_array_new_checked (domain, mono_defaults.char_class, n, &error);
1176 if (mono_error_set_pending_exception (&error))
1179 for (i = 0; i < n; ++ i)
1180 mono_array_set (chars, gunichar2, i, invalid_path_chars [i]);
1185 void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position,
1186 gint64 length, gint32 *error)
1188 *error=ERROR_SUCCESS;
1189 mono_w32file_lock (handle, position, length, error);
1192 void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
1193 gint64 length, gint32 *error)
1195 *error=ERROR_SUCCESS;
1196 mono_w32file_unlock (handle, position, length, error);
1199 //Support for io-layer free mmap'd files.
1201 #if defined (TARGET_IOS) || defined (TARGET_ANDROID)
1204 mono_filesize_from_path (MonoString *string)
1209 char *path = mono_string_to_utf8_checked (string, &error);
1210 mono_error_raise_exception (&error); /* OK to throw, external only without a good alternative */
1213 if (stat (path, &buf) == -1)
1216 res = (gint64)buf.st_size;
1225 mono_filesize_from_fd (int fd)
1231 res = fstat (fd, &buf);
1237 return (gint64)buf.st_size;
1243 void mono_w32handle_dump (void);
1245 void ves_icall_System_IO_MonoIO_DumpHandles (void)
1247 mono_w32handle_dump ();
1249 #endif /* !HOST_WIN32 */