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 *ioerror,
468 WIN32_FIND_DATA data;
470 IncrementalFind *ifh;
473 *ioerror = ERROR_SUCCESS;
475 find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data);
477 if (find_handle == INVALID_HANDLE_VALUE) {
478 gint32 find_error = GetLastError ();
481 if (find_error == ERROR_FILE_NOT_FOUND)
484 *ioerror = find_error;
488 ifh = g_new (IncrementalFind, 1);
489 ifh->find_handle = find_handle;
490 ifh->utf8_path = mono_string_to_utf8_checked (path, &error);
491 if (mono_error_set_pending_exception (&error))
493 ifh->domain = mono_domain_get ();
496 while (incremental_find_check_match (ifh, &data, &result) == 0){
497 if (FindNextFile (find_handle, &data) == FALSE){
498 int e = GetLastError ();
499 if (e != ERROR_NO_MORE_FILES)
504 *result_attr = data.dwFileAttributes;
509 /* FIXME make gc suspendable */
511 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint32 *error)
513 IncrementalFind *ifh = (IncrementalFind *)handle;
514 WIN32_FIND_DATA data;
517 *error = ERROR_SUCCESS;
519 if (FindNextFile (ifh->find_handle, &data) == FALSE){
520 int e = GetLastError ();
521 if (e != ERROR_NO_MORE_FILES)
525 } while (incremental_find_check_match (ifh, &data, &result) == 0);
527 *result_attr = data.dwFileAttributes;
532 ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
534 IncrementalFind *ifh = (IncrementalFind *)handle;
538 if (FindClose (ifh->find_handle) == FALSE){
539 error = GetLastError ();
541 error = ERROR_SUCCESS;
542 g_free (ifh->utf8_path);
550 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *io_error)
557 len = MAX_PATH + 1; /*FIXME this is too smal under most unix systems.*/
558 buf = g_new (gunichar2, len);
560 mono_error_init (&error);
561 *io_error=ERROR_SUCCESS;
564 res_len = GetCurrentDirectory (len, buf);
565 if (res_len > len) { /*buf is too small.*/
566 int old_res_len = res_len;
568 buf = g_new (gunichar2, res_len);
569 res_len = GetCurrentDirectory (res_len, buf) == old_res_len;
577 result = mono_string_new_utf16_checked (mono_domain_get (), buf, len, &error);
579 *io_error=GetLastError ();
583 mono_error_set_pending_exception (&error);
588 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
593 *error=ERROR_SUCCESS;
595 ret=SetCurrentDirectory (mono_string_chars (path));
597 *error=GetLastError ();
604 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest,
610 *error=ERROR_SUCCESS;
612 ret=MoveFile (mono_string_chars (path), mono_string_chars (dest));
614 *error=GetLastError ();
622 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
623 MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
627 gunichar2 *utf16_sourceFileName = NULL, *utf16_destinationFileName = NULL, *utf16_destinationBackupFileName = NULL;
628 guint32 replaceFlags = REPLACEFILE_WRITE_THROUGH;
632 utf16_sourceFileName = mono_string_chars (sourceFileName);
633 if (destinationFileName)
634 utf16_destinationFileName = mono_string_chars (destinationFileName);
635 if (destinationBackupFileName)
636 utf16_destinationBackupFileName = mono_string_chars (destinationBackupFileName);
638 *error = ERROR_SUCCESS;
639 if (ignoreMetadataErrors)
640 replaceFlags |= REPLACEFILE_IGNORE_MERGE_ERRORS;
642 /* FIXME: source and destination file names must not be NULL, but apparently they might be! */
643 ret = ReplaceFile (utf16_destinationFileName, utf16_sourceFileName, utf16_destinationBackupFileName,
644 replaceFlags, NULL, NULL);
646 *error = GetLastError ();
653 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
654 MonoBoolean overwrite, gint32 *error)
659 *error=ERROR_SUCCESS;
661 ret=CopyFile (mono_string_chars (path), mono_string_chars (dest), !overwrite);
663 *error=GetLastError ();
671 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error)
676 *error=ERROR_SUCCESS;
678 ret=DeleteFile (mono_string_chars (path));
680 *error=GetLastError ();
688 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error)
693 *error=ERROR_SUCCESS;
695 ret=get_file_attributes (mono_string_chars (path));
698 * The definition of INVALID_FILE_ATTRIBUTES in the cygwin win32
699 * headers is wrong, hence this temporary workaround.
701 * http://cygwin.com/ml/cygwin/2003-09/msg01771.html
704 /* if(ret==INVALID_FILE_ATTRIBUTES) { */
705 *error=GetLastError ();
713 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
719 *error=ERROR_SUCCESS;
721 ret=SetFileAttributes (mono_string_chars (path),
722 convert_attrs ((MonoFileAttributes)attrs));
724 *error=GetLastError ();
732 ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error)
737 *error=ERROR_SUCCESS;
739 ret=GetFileType (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=GetLastError ();
752 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat,
756 WIN32_FILE_ATTRIBUTE_DATA data;
759 *error=ERROR_SUCCESS;
761 result = get_file_attributes_ex (mono_string_chars (path), &data);
764 convert_win32_file_attribute_data (&data, stat);
766 *error=GetLastError ();
767 memset (stat, 0, sizeof (MonoIOStat));
775 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
776 gint32 access_mode, gint32 share, gint32 options,
780 int attributes, attrs;
784 chars = mono_string_chars (filename);
785 *error=ERROR_SUCCESS;
788 if (options & FileOptions_Encrypted)
789 attributes = FILE_ATTRIBUTE_ENCRYPTED;
791 attributes = FILE_ATTRIBUTE_NORMAL;
792 if (options & FileOptions_DeleteOnClose)
793 attributes |= FILE_FLAG_DELETE_ON_CLOSE;
794 if (options & FileOptions_SequentialScan)
795 attributes |= FILE_FLAG_SEQUENTIAL_SCAN;
796 if (options & FileOptions_RandomAccess)
797 attributes |= FILE_FLAG_RANDOM_ACCESS;
799 if (options & FileOptions_Temporary)
800 attributes |= FILE_ATTRIBUTE_TEMPORARY;
802 /* Not sure if we should set FILE_FLAG_OVERLAPPED, how does this mix with the "Async" bool here? */
803 if (options & FileOptions_Asynchronous)
804 attributes |= FILE_FLAG_OVERLAPPED;
806 if (options & FileOptions_WriteThrough)
807 attributes |= FILE_FLAG_WRITE_THROUGH;
809 attributes = FILE_ATTRIBUTE_NORMAL;
811 /* If we're opening a directory we need to set the extra flag
813 attrs = get_file_attributes (chars);
814 if (attrs != INVALID_FILE_ATTRIBUTES) {
815 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
816 attributes |= FILE_FLAG_BACKUP_SEMANTICS;
820 ret=CreateFile (chars, convert_access ((MonoFileAccess)access_mode),
821 convert_share ((MonoFileShare)share), NULL, convert_mode ((MonoFileMode)mode),
823 if(ret==INVALID_HANDLE_VALUE) {
824 *error=GetLastError ();
832 ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error)
837 *error=ERROR_SUCCESS;
839 ret=CloseHandle (handle);
841 *error=GetLastError ();
849 ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
850 gint32 dest_offset, gint32 count,
857 *error=ERROR_SUCCESS;
859 MONO_CHECK_ARG_NULL (dest, 0);
861 if (dest_offset > mono_array_length (dest) - count) {
862 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
866 buffer = mono_array_addr (dest, guchar, dest_offset);
869 result = ReadFile (handle, buffer, count, &n, NULL);
873 *error=GetLastError ();
881 ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
882 gint32 src_offset, gint32 count,
889 *error=ERROR_SUCCESS;
891 MONO_CHECK_ARG_NULL (src, 0);
893 if (src_offset > mono_array_length (src) - count) {
894 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
898 buffer = mono_array_addr (src, guchar, src_offset);
900 result = WriteFile (handle, buffer, count, &n, NULL);
904 *error=GetLastError ();
912 ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
918 *error=ERROR_SUCCESS;
920 offset_hi = offset >> 32;
921 offset = SetFilePointer (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
922 convert_seekorigin ((MonoSeekOrigin)origin));
924 if(offset==INVALID_SET_FILE_POINTER) {
925 *error=GetLastError ();
929 return offset | ((gint64)offset_hi << 32);
933 ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error)
938 *error=ERROR_SUCCESS;
940 ret=FlushFileBuffers (handle);
942 *error=GetLastError ();
950 ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error)
956 *error=ERROR_SUCCESS;
958 length = GetFileSize (handle, &length_hi);
959 if(length==INVALID_FILE_SIZE) {
960 *error=GetLastError ();
964 return length | ((gint64)length_hi << 32);
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 = SetFilePointer (handle, 0, &offset_hi, FILE_CURRENT);
983 if(offset==INVALID_SET_FILE_POINTER) {
984 *error=GetLastError ();
988 /* extend or truncate */
990 length_hi = length >> 32;
991 offset_set=SetFilePointer (handle, length & 0xFFFFFFFF, &length_hi,
993 if(offset_set==INVALID_SET_FILE_POINTER) {
994 *error=GetLastError ();
998 result = SetEndOfFile (handle);
1000 *error=GetLastError ();
1004 /* restore file pointer */
1006 offset_set=SetFilePointer (handle, offset & 0xFFFFFFFF, &offset_hi,
1008 if(offset_set==INVALID_SET_FILE_POINTER) {
1009 *error=GetLastError ();
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 *last_access_filetime;
1024 const FILETIME *last_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 last_access_filetime = NULL;
1037 last_access_filetime = (FILETIME *)&last_access_time;
1039 if (last_write_time < 0)
1040 last_write_filetime = NULL;
1042 last_write_filetime = (FILETIME *)&last_write_time;
1044 ret=SetFileTime (handle, creation_filetime, last_access_filetime, last_write_filetime);
1046 *error=GetLastError ();
1054 ves_icall_System_IO_MonoIO_get_ConsoleOutput ()
1056 return GetStdHandle (STD_OUTPUT_HANDLE);
1060 ves_icall_System_IO_MonoIO_get_ConsoleInput ()
1062 return GetStdHandle (STD_INPUT_HANDLE);
1066 ves_icall_System_IO_MonoIO_get_ConsoleError ()
1068 return GetStdHandle (STD_ERROR_HANDLE);
1072 ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle, HANDLE *write_handle, gint32 *error)
1074 SECURITY_ATTRIBUTES attr;
1077 attr.nLength=sizeof(SECURITY_ATTRIBUTES);
1078 attr.bInheritHandle=TRUE;
1079 attr.lpSecurityDescriptor=NULL;
1082 ret=CreatePipe (read_handle, write_handle, &attr, 0);
1086 *error = GetLastError ();
1087 /* FIXME: throw an exception? */
1095 ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle, HANDLE source_handle,
1096 HANDLE target_process_handle, HANDLE *target_handle, gint32 access, gint32 inherit, gint32 options, gint32 *error)
1098 /* This is only used on Windows */
1102 ret=DuplicateHandle (source_process_handle, source_handle, target_process_handle, target_handle, access, inherit, options);
1106 *error = GetLastError ();
1107 /* FIXME: throw an exception? */
1115 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
1117 #if defined (TARGET_WIN32)
1118 return (gunichar2) ':'; /* colon */
1120 return (gunichar2) '/'; /* forward slash */
1125 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
1127 #if defined (TARGET_WIN32)
1128 return (gunichar2) '\\'; /* backslash */
1130 return (gunichar2) '/'; /* forward slash */
1135 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
1137 #if defined (TARGET_WIN32)
1138 return (gunichar2) '/'; /* forward slash */
1140 if (IS_PORTABILITY_SET)
1141 return (gunichar2) '\\'; /* backslash */
1143 return (gunichar2) '/'; /* forward slash */
1148 ves_icall_System_IO_MonoIO_get_PathSeparator ()
1150 #if defined (TARGET_WIN32)
1151 return (gunichar2) ';'; /* semicolon */
1153 return (gunichar2) ':'; /* colon */
1157 static const gunichar2
1158 invalid_path_chars [] = {
1159 #if defined (TARGET_WIN32)
1160 0x0022, /* double quote, which seems allowed in MS.NET but should be rejected */
1161 0x003c, /* less than */
1162 0x003e, /* greater than */
1179 ves_icall_System_IO_MonoIO_get_InvalidPathChars ()
1186 domain = mono_domain_get ();
1187 n = sizeof (invalid_path_chars) / sizeof (gunichar2);
1188 chars = mono_array_new_checked (domain, mono_defaults.char_class, n, &error);
1189 if (mono_error_set_pending_exception (&error))
1192 for (i = 0; i < n; ++ i)
1193 mono_array_set (chars, gunichar2, i, invalid_path_chars [i]);
1198 void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position,
1199 gint64 length, gint32 *error)
1204 *error=ERROR_SUCCESS;
1206 ret=LockFile (handle, position & 0xFFFFFFFF, position >> 32,
1207 length & 0xFFFFFFFF, length >> 32);
1209 *error = GetLastError ();
1215 void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
1216 gint64 length, gint32 *error)
1221 *error=ERROR_SUCCESS;
1223 ret=UnlockFile (handle, position & 0xFFFFFFFF, position >> 32,
1224 length & 0xFFFFFFFF, length >> 32);
1226 *error = GetLastError ();
1232 //Support for io-layer free mmap'd files.
1234 #if defined (TARGET_IOS) || defined (TARGET_ANDROID)
1237 mono_filesize_from_path (MonoString *string)
1242 char *path = mono_string_to_utf8_checked (string, &error);
1243 mono_error_raise_exception (&error); /* OK to throw, external only without a good alternative */
1246 if (stat (path, &buf) == -1)
1249 res = (gint64)buf.st_size;
1258 mono_filesize_from_fd (int fd)
1264 res = fstat (fd, &buf);
1270 return (gint64)buf.st_size;
1275 void _wapi_handle_dump (void);
1277 void ves_icall_System_IO_MonoIO_DumpHandles (void)
1280 _wapi_handle_dump ();