2 * file-io-windows-uwp.c: UWP file-io support for Mono.
4 * Copyright 2016 Microsoft
5 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
10 #if G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT)
12 #include "mono/metadata/file-io-windows-internals.h"
15 mono_file_io_move_file (gunichar2 *path, gunichar2 *dest, gint32 *error)
17 gboolean result = FALSE;
20 result = MoveFileEx (path, dest, MOVEFILE_COPY_ALLOWED);
21 if (result == FALSE) {
22 *error=GetLastError ();
30 mono_file_io_replace_file (gunichar2 *destinationFileName, gunichar2 *sourceFileName,
31 gunichar2 *destinationBackupFileName, guint32 flags, gint32 *error)
33 gboolean result = FALSE;
36 result = ReplaceFile (destinationFileName, sourceFileName, destinationBackupFileName, flags, NULL, NULL);
37 if (result == FALSE) {
38 *error=GetLastError ();
46 mono_file_io_copy_file (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32 *error)
48 gboolean result = FALSE;
49 COPYFILE2_EXTENDED_PARAMETERS copy_param = {0};
51 copy_param.dwSize = sizeof (COPYFILE2_EXTENDED_PARAMETERS);
52 copy_param.dwCopyFlags = (!overwrite) ? COPY_FILE_FAIL_IF_EXISTS : 0;
56 result = SUCCEEDED (CopyFile2 (path, dest, ©_param));
57 if (result == FALSE) {
58 *error=GetLastError ();
66 mono_file_io_get_file_size (HANDLE handle, gint32 *error)
72 if (!GetFileSizeEx (handle, &length)) {
73 *error=GetLastError ();
74 length.QuadPart = INVALID_FILE_SIZE;
78 return length.QuadPart;
82 mono_file_io_lock_file (HANDLE handle, gint64 position, gint64 length, gint32 *error)
84 gboolean result = FALSE;
87 result = LockFile (handle, position & 0xFFFFFFFF, position >> 32,
88 length & 0xFFFFFFFF, length >> 32);
90 if (result == FALSE) {
91 *error = GetLastError ();
99 mono_file_io_unlock_file (HANDLE handle, gint64 position, gint64 length, gint32 *error)
101 gboolean result = FALSE;
104 result = UnlockFile (handle, position & 0xFFFFFFFF, position >> 32,
105 length & 0xFFFFFFFF, length >> 32);
107 if (result == FALSE) {
108 *error = GetLastError ();
115 #else /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */
118 // Quiet Visual Studio linker warning, LNK4221, in cases when this source file intentional ends up empty.
119 void __mono_win32_file_io_windows_uwp_quiet_lnk4221(void) {}
121 #endif /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */