w32file-win32.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /**
  2. * \file
  3. * Windows File IO internal calls.
  4. *
  5. * Copyright 2016 Microsoft
  6. * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  7. */
  8. #include <config.h>
  9. #include <glib.h>
  10. #include <winsock2.h>
  11. #include <windows.h>
  12. #include <mono/utils/w32subset.h>
  13. #include "icall-decl.h"
  14. void
  15. mono_w32file_init (void)
  16. {
  17. }
  18. void
  19. mono_w32file_cleanup (void)
  20. {
  21. }
  22. gunichar2
  23. ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
  24. {
  25. return (gunichar2) ':'; /* colon */
  26. }
  27. gunichar2
  28. ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
  29. {
  30. return (gunichar2) '\\'; /* backslash */
  31. }
  32. gunichar2
  33. ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
  34. {
  35. return (gunichar2) '/'; /* forward slash */
  36. }
  37. gunichar2
  38. ves_icall_System_IO_MonoIO_get_PathSeparator ()
  39. {
  40. return (gunichar2) ';'; /* semicolon */
  41. }
  42. void ves_icall_System_IO_MonoIO_DumpHandles (void)
  43. {
  44. return;
  45. }
  46. gpointer
  47. mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs)
  48. {
  49. gpointer res;
  50. MONO_ENTER_GC_SAFE;
  51. res = CreateFileW (name, fileaccess, sharemode, NULL, createmode, attrs, NULL);
  52. MONO_EXIT_GC_SAFE;
  53. return res;
  54. }
  55. gboolean
  56. mono_w32file_cancel (gpointer handle)
  57. {
  58. return CancelIoEx (handle, NULL);
  59. }
  60. gboolean
  61. mono_w32file_close (gpointer handle)
  62. {
  63. gboolean res;
  64. MONO_ENTER_GC_SAFE;
  65. res = CloseHandle (handle);
  66. MONO_EXIT_GC_SAFE;
  67. return res;
  68. }
  69. gboolean
  70. mono_w32file_delete (const gunichar2 *name)
  71. {
  72. gboolean res;
  73. MONO_ENTER_GC_SAFE;
  74. res = DeleteFileW (name);
  75. MONO_EXIT_GC_SAFE;
  76. return res;
  77. }
  78. // See win32_wait_interrupt_handler for details.
  79. static void
  80. win32_io_interrupt_handler (gpointer ignored)
  81. {
  82. }
  83. gboolean
  84. mono_w32file_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread, gint32 *win32error)
  85. {
  86. gboolean res;
  87. MonoThreadInfo *info = mono_thread_info_current ();
  88. gboolean alerted = FALSE;
  89. if (info) {
  90. mono_thread_info_install_interrupt (win32_io_interrupt_handler, NULL, &alerted);
  91. if (alerted) {
  92. SetLastError (ERROR_OPERATION_ABORTED);
  93. *win32error = ERROR_OPERATION_ABORTED;
  94. return FALSE;
  95. }
  96. mono_win32_enter_blocking_io_call (info, handle);
  97. }
  98. MONO_ENTER_GC_SAFE;
  99. if (info && mono_thread_info_is_interrupt_state (info)) {
  100. res = FALSE;
  101. SetLastError (ERROR_OPERATION_ABORTED);
  102. } else {
  103. res = ReadFile (handle, buffer, numbytes, (PDWORD)bytesread, NULL);
  104. }
  105. if (!res)
  106. *win32error = GetLastError ();
  107. MONO_EXIT_GC_SAFE;
  108. if (info) {
  109. mono_win32_leave_blocking_io_call (info, handle);
  110. mono_thread_info_uninstall_interrupt (&alerted);
  111. }
  112. return res;
  113. }
  114. gboolean
  115. mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten, gint32 *win32error)
  116. {
  117. gboolean res;
  118. MonoThreadInfo *info = mono_thread_info_current ();
  119. gboolean alerted = FALSE;
  120. if (info) {
  121. mono_thread_info_install_interrupt (win32_io_interrupt_handler, NULL, &alerted);
  122. if (alerted) {
  123. SetLastError (ERROR_OPERATION_ABORTED);
  124. *win32error = ERROR_OPERATION_ABORTED;
  125. return FALSE;
  126. }
  127. mono_win32_enter_blocking_io_call (info, handle);
  128. }
  129. MONO_ENTER_GC_SAFE;
  130. if (info && mono_thread_info_is_interrupt_state (info)) {
  131. res = FALSE;
  132. SetLastError (ERROR_OPERATION_ABORTED);
  133. } else {
  134. res = WriteFile (handle, buffer, numbytes, (PDWORD)byteswritten, NULL);
  135. }
  136. if (!res)
  137. *win32error = GetLastError ();
  138. MONO_EXIT_GC_SAFE;
  139. if (info) {
  140. mono_win32_leave_blocking_io_call (info, handle);
  141. mono_thread_info_uninstall_interrupt (&alerted);
  142. }
  143. return res;
  144. }
  145. gboolean
  146. mono_w32file_flush (gpointer handle)
  147. {
  148. gboolean res;
  149. MONO_ENTER_GC_SAFE;
  150. res = FlushFileBuffers (handle);
  151. MONO_EXIT_GC_SAFE;
  152. return res;
  153. }
  154. gboolean
  155. mono_w32file_truncate (gpointer handle)
  156. {
  157. gboolean res;
  158. MONO_ENTER_GC_SAFE;
  159. res = SetEndOfFile (handle);
  160. MONO_EXIT_GC_SAFE;
  161. return res;
  162. }
  163. guint32
  164. mono_w32file_seek (gpointer handle, gint32 movedistance, gint32 *highmovedistance, guint32 method)
  165. {
  166. guint32 res;
  167. MONO_ENTER_GC_SAFE;
  168. res = SetFilePointer (handle, movedistance, (PLONG)highmovedistance, method);
  169. MONO_EXIT_GC_SAFE;
  170. return res;
  171. }
  172. gint
  173. mono_w32file_get_type (gpointer handle)
  174. {
  175. gint res;
  176. MONO_ENTER_GC_SAFE;
  177. res = GetFileType (handle);
  178. MONO_EXIT_GC_SAFE;
  179. return res;
  180. }
  181. gboolean
  182. mono_w32file_set_times (gpointer handle, const FILETIME *create_time, const FILETIME *access_time, const FILETIME *write_time)
  183. {
  184. gboolean res;
  185. MONO_ENTER_GC_SAFE;
  186. res = SetFileTime (handle, create_time, access_time, write_time);
  187. MONO_EXIT_GC_SAFE;
  188. return res;
  189. }
  190. gboolean
  191. mono_w32file_filetime_to_systemtime (const FILETIME *file_time, SYSTEMTIME *system_time)
  192. {
  193. gboolean res;
  194. MONO_ENTER_GC_SAFE;
  195. res = FileTimeToSystemTime (file_time, system_time);
  196. MONO_EXIT_GC_SAFE;
  197. return res;
  198. }
  199. gpointer
  200. mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATAW *find_data)
  201. {
  202. gpointer res;
  203. MONO_ENTER_GC_SAFE;
  204. res = FindFirstFileW (pattern, find_data);
  205. MONO_EXIT_GC_SAFE;
  206. return res;
  207. }
  208. gboolean
  209. mono_w32file_find_next (gpointer handle, WIN32_FIND_DATAW *find_data)
  210. {
  211. gboolean res;
  212. MONO_ENTER_GC_SAFE;
  213. res = FindNextFileW (handle, find_data);
  214. MONO_EXIT_GC_SAFE;
  215. return res;
  216. }
  217. gboolean
  218. mono_w32file_find_close (gpointer handle)
  219. {
  220. gboolean res;
  221. MONO_ENTER_GC_SAFE;
  222. res = FindClose (handle);
  223. MONO_EXIT_GC_SAFE;
  224. return res;
  225. }
  226. gboolean
  227. mono_w32file_create_directory (const gunichar2 *name)
  228. {
  229. gboolean res;
  230. MONO_ENTER_GC_SAFE;
  231. res = CreateDirectoryW (name, NULL);
  232. MONO_EXIT_GC_SAFE;
  233. return res;
  234. }
  235. gboolean
  236. mono_w32file_remove_directory (const gunichar2 *name)
  237. {
  238. gboolean res;
  239. MONO_ENTER_GC_SAFE;
  240. res = RemoveDirectoryW (name);
  241. MONO_EXIT_GC_SAFE;
  242. return res;
  243. }
  244. /*
  245. * GetFileAttributes|Ex () seems to try opening the file, which might lead to sharing violation errors, whereas
  246. * FindFirstFile always succeeds.
  247. */
  248. guint32
  249. mono_w32file_get_attributes (const gunichar2 *name)
  250. {
  251. guint32 res;
  252. HANDLE find_handle;
  253. WIN32_FIND_DATAW find_data;
  254. MONO_ENTER_GC_SAFE;
  255. res = GetFileAttributesW (name);
  256. if (res == INVALID_FILE_ATTRIBUTES && GetLastError () == ERROR_SHARING_VIOLATION) {
  257. find_handle = FindFirstFileW (name, &find_data);
  258. if (find_handle != INVALID_HANDLE_VALUE) {
  259. FindClose (find_handle);
  260. res = find_data.dwFileAttributes;
  261. } else {
  262. res = INVALID_FILE_ATTRIBUTES;
  263. }
  264. }
  265. MONO_EXIT_GC_SAFE;
  266. return res;
  267. }
  268. static gint64
  269. convert_filetime (const FILETIME *filetime)
  270. {
  271. return (gint64) ((((guint64) filetime->dwHighDateTime) << 32) + filetime->dwLowDateTime);
  272. }
  273. gboolean
  274. mono_w32file_get_attributes_ex (const gunichar2 *name, MonoIOStat *stat)
  275. {
  276. gboolean res;
  277. HANDLE find_handle;
  278. WIN32_FIND_DATAW find_data;
  279. WIN32_FILE_ATTRIBUTE_DATA file_attribute_data;
  280. MONO_ENTER_GC_SAFE;
  281. res = GetFileAttributesExW (name, GetFileExInfoStandard, &file_attribute_data);
  282. if (res) {
  283. stat->attributes = file_attribute_data.dwFileAttributes;
  284. stat->creation_time = convert_filetime (&file_attribute_data.ftCreationTime);
  285. stat->last_access_time = convert_filetime (&file_attribute_data.ftLastAccessTime);
  286. stat->last_write_time = convert_filetime (&file_attribute_data.ftLastWriteTime);
  287. stat->length = ((gint64)file_attribute_data.nFileSizeHigh << 32) | file_attribute_data.nFileSizeLow;
  288. } else if (!res && GetLastError () == ERROR_SHARING_VIOLATION) {
  289. find_handle = FindFirstFileW (name, &find_data);
  290. if (find_handle != INVALID_HANDLE_VALUE) {
  291. FindClose (find_handle);
  292. stat->attributes = find_data.dwFileAttributes;
  293. stat->creation_time = convert_filetime (&find_data.ftCreationTime);
  294. stat->last_access_time = convert_filetime (&find_data.ftLastAccessTime);
  295. stat->last_write_time = convert_filetime (&find_data.ftLastWriteTime);
  296. stat->length = ((gint64)find_data.nFileSizeHigh << 32) | find_data.nFileSizeLow;
  297. res = TRUE;
  298. }
  299. }
  300. MONO_EXIT_GC_SAFE;
  301. return res;
  302. }
  303. gboolean
  304. mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs)
  305. {
  306. gboolean res;
  307. MONO_ENTER_GC_SAFE;
  308. res = SetFileAttributesW (name, attrs);
  309. MONO_EXIT_GC_SAFE;
  310. return res;
  311. }
  312. guint32
  313. mono_w32file_get_cwd (guint32 length, gunichar2 *buffer)
  314. {
  315. guint32 res;
  316. MONO_ENTER_GC_SAFE;
  317. res = GetCurrentDirectoryW (length, buffer);
  318. MONO_EXIT_GC_SAFE;
  319. return res;
  320. }
  321. gboolean
  322. mono_w32file_set_cwd (const gunichar2 *path)
  323. {
  324. gboolean res;
  325. MONO_ENTER_GC_SAFE;
  326. res = SetCurrentDirectoryW (path);
  327. MONO_EXIT_GC_SAFE;
  328. return res;
  329. }
  330. gboolean
  331. mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size)
  332. {
  333. gboolean res;
  334. SECURITY_ATTRIBUTES attr;
  335. attr.nLength = sizeof(SECURITY_ATTRIBUTES);
  336. attr.bInheritHandle = TRUE;
  337. attr.lpSecurityDescriptor = NULL;
  338. MONO_ENTER_GC_SAFE;
  339. res = CreatePipe (readpipe, writepipe, &attr, size);
  340. MONO_EXIT_GC_SAFE;
  341. return res;
  342. }
  343. #ifndef PLATFORM_NO_DRIVEINFO
  344. gboolean
  345. mono_w32file_get_disk_free_space (const gunichar2 *path_name, guint64 *free_bytes_avail, guint64 *total_number_of_bytes, guint64 *total_number_of_free_bytes)
  346. {
  347. gboolean result;
  348. ULARGE_INTEGER wapi_free_bytes_avail = { 0 };
  349. ULARGE_INTEGER wapi_total_number_of_bytes = { 0 };
  350. ULARGE_INTEGER wapi_total_number_of_free_bytes = { 0 };
  351. g_assert (free_bytes_avail);
  352. g_assert (total_number_of_bytes);
  353. g_assert (total_number_of_free_bytes);
  354. MONO_ENTER_GC_SAFE;
  355. result = GetDiskFreeSpaceExW (path_name, &wapi_free_bytes_avail, &wapi_total_number_of_bytes, &wapi_total_number_of_free_bytes);
  356. MONO_EXIT_GC_SAFE;
  357. *free_bytes_avail = wapi_free_bytes_avail.QuadPart;
  358. *total_number_of_bytes = wapi_total_number_of_bytes.QuadPart;
  359. *total_number_of_free_bytes = wapi_total_number_of_free_bytes.QuadPart;
  360. return result;
  361. }
  362. #endif // PLATFORM_NO_DRIVEINFO
  363. gboolean
  364. mono_w32file_get_file_system_type (const gunichar2 *path, gunichar2 *fsbuffer, gint fsbuffersize)
  365. {
  366. gboolean res;
  367. MONO_ENTER_GC_SAFE;
  368. res = GetVolumeInformationW (path, NULL, 0, NULL, NULL, NULL, fsbuffer, fsbuffersize);
  369. MONO_EXIT_GC_SAFE;
  370. return res;
  371. }
  372. #if HAVE_API_SUPPORT_WIN32_MOVE_FILE
  373. gboolean
  374. mono_w32file_move (const gunichar2 *path, const gunichar2 *dest, gint32 *error)
  375. {
  376. gboolean result = FALSE;
  377. MONO_ENTER_GC_SAFE;
  378. result = MoveFileW (path, dest);
  379. if (!result)
  380. *error = GetLastError ();
  381. MONO_EXIT_GC_SAFE;
  382. return result;
  383. }
  384. #elif HAVE_API_SUPPORT_WIN32_MOVE_FILE_EX
  385. gboolean
  386. mono_w32file_move (const gunichar2 *path, const gunichar2 *dest, gint32 *error)
  387. {
  388. gboolean result = FALSE;
  389. MONO_ENTER_GC_SAFE;
  390. result = MoveFileExW (path, dest, MOVEFILE_COPY_ALLOWED);
  391. if (!result) {
  392. *error = GetLastError ();
  393. }
  394. MONO_EXIT_GC_SAFE;
  395. return result;
  396. }
  397. #elif !HAVE_EXTERN_DEFINED_WIN32_MOVE_FILE && !HAVE_EXTERN_DEFINED_WIN32_MOVE_FILE_EX
  398. gboolean
  399. mono_w32file_move (const gunichar2 *path, const gunichar2 *dest, gint32 *error)
  400. {
  401. g_unsupported_api ("MoveFile, MoveFileEx");
  402. *error = ERROR_NOT_SUPPORTED;
  403. SetLastError (ERROR_NOT_SUPPORTED);
  404. return FALSE;
  405. }
  406. #endif
  407. #if HAVE_API_SUPPORT_WIN32_REPLACE_FILE
  408. gboolean
  409. mono_w32file_replace (const gunichar2 *destination_file_name, const gunichar2 *source_file_name, const gunichar2 *destination_backup_file_name, guint32 flags, gint32 *error)
  410. {
  411. gboolean result = FALSE;
  412. MONO_ENTER_GC_SAFE;
  413. result = ReplaceFileW (destination_file_name, source_file_name, destination_backup_file_name, flags, NULL, NULL);
  414. if (!result)
  415. *error = GetLastError ();
  416. MONO_EXIT_GC_SAFE;
  417. return result;
  418. }
  419. #elif !HAVE_EXTERN_DEFINED_WIN32_REPLACE_FILE
  420. gboolean
  421. mono_w32file_replace (const gunichar2 *destination_file_name, const gunichar2 *source_file_name, const gunichar2 *destination_backup_file_name, guint32 flags, gint32 *error)
  422. {
  423. g_unsupported_api ("ReplaceFile");
  424. *error = ERROR_NOT_SUPPORTED;
  425. SetLastError (ERROR_NOT_SUPPORTED);
  426. return FALSE;
  427. }
  428. #endif
  429. #if HAVE_API_SUPPORT_WIN32_COPY_FILE
  430. gboolean
  431. mono_w32file_copy (const gunichar2 *path, const gunichar2 *dest, gboolean overwrite, gint32 *error)
  432. {
  433. gboolean result = FALSE;
  434. MONO_ENTER_GC_SAFE;
  435. result = CopyFileW (path, dest, !overwrite);
  436. if (!result)
  437. *error = GetLastError ();
  438. MONO_EXIT_GC_SAFE;
  439. return result;
  440. }
  441. #elif HAVE_API_SUPPORT_WIN32_COPY_FILE2
  442. gboolean
  443. mono_w32file_copy (const gunichar2 *path, const gunichar2 *dest, gboolean overwrite, gint32 *error)
  444. {
  445. gboolean result = FALSE;
  446. COPYFILE2_EXTENDED_PARAMETERS copy_param = {0};
  447. copy_param.dwSize = sizeof (COPYFILE2_EXTENDED_PARAMETERS);
  448. copy_param.dwCopyFlags = (!overwrite) ? COPY_FILE_FAIL_IF_EXISTS : 0;
  449. MONO_ENTER_GC_SAFE;
  450. result = SUCCEEDED (CopyFile2 (path, dest, &copy_param));
  451. if (result == FALSE) {
  452. *error=GetLastError ();
  453. }
  454. MONO_EXIT_GC_SAFE;
  455. return result;
  456. }
  457. #elif !HAVE_EXTERN_DEFINED_WIN32_COPY_FILE && !HAVE_EXTERN_DEFINED_WIN32_COPY_FILE2
  458. gboolean
  459. mono_w32file_copy (const gunichar2 *path, const gunichar2 *dest, gboolean overwrite, gint32 *error)
  460. {
  461. g_unsupported_api ("CopyFile, CopyFile2");
  462. *error = ERROR_NOT_SUPPORTED;
  463. SetLastError (ERROR_NOT_SUPPORTED);
  464. return FALSE;
  465. }
  466. #endif
  467. #if HAVE_API_SUPPORT_WIN32_LOCK_FILE
  468. gboolean
  469. mono_w32file_lock (gpointer handle, gint64 position, gint64 length, gint32 *error)
  470. {
  471. gboolean result;
  472. MONO_ENTER_GC_SAFE;
  473. result = LockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32);
  474. if (!result)
  475. *error = GetLastError ();
  476. MONO_EXIT_GC_SAFE;
  477. return result;
  478. }
  479. #elif !HAVE_EXTERN_DEFINED_WIN32_LOCK_FILE
  480. gboolean
  481. mono_w32file_lock (gpointer handle, gint64 position, gint64 length, gint32 *error)
  482. {
  483. g_unsupported_api ("LockFile");
  484. *error = ERROR_NOT_SUPPORTED;
  485. SetLastError (ERROR_NOT_SUPPORTED);
  486. return FALSE;
  487. }
  488. #endif
  489. #if HAVE_API_SUPPORT_WIN32_UNLOCK_FILE
  490. gboolean
  491. mono_w32file_unlock (gpointer handle, gint64 position, gint64 length, gint32 *error)
  492. {
  493. gboolean result;
  494. MONO_ENTER_GC_SAFE;
  495. result = UnlockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32);
  496. if (!result)
  497. *error = GetLastError ();
  498. MONO_EXIT_GC_SAFE;
  499. return result;
  500. }
  501. #elif !HAVE_EXTERN_DEFINED_WIN32_UNLOCK_FILE
  502. gboolean
  503. mono_w32file_unlock (gpointer handle, gint64 position, gint64 length, gint32 *error)
  504. {
  505. g_unsupported_api ("UnlockFile");
  506. *error = ERROR_NOT_SUPPORTED;
  507. SetLastError (ERROR_NOT_SUPPORTED);
  508. return FALSE;
  509. }
  510. #endif
  511. #if HAVE_API_SUPPORT_WIN32_GET_STD_HANDLE
  512. gpointer
  513. mono_w32file_get_console_input (void)
  514. {
  515. HANDLE res;
  516. MONO_ENTER_GC_SAFE;
  517. res = GetStdHandle (STD_INPUT_HANDLE);
  518. MONO_EXIT_GC_SAFE;
  519. return res;
  520. }
  521. gpointer
  522. mono_w32file_get_console_output (void)
  523. {
  524. HANDLE res;
  525. MONO_ENTER_GC_SAFE;
  526. res = GetStdHandle (STD_OUTPUT_HANDLE);
  527. MONO_EXIT_GC_SAFE;
  528. return res;
  529. }
  530. gpointer
  531. mono_w32file_get_console_error (void)
  532. {
  533. HANDLE res;
  534. MONO_ENTER_GC_SAFE;
  535. res = GetStdHandle (STD_ERROR_HANDLE);
  536. MONO_EXIT_GC_SAFE;
  537. return res;
  538. }
  539. #elif !HAVE_EXTERN_DEFINED_WIN32_GET_STD_HANDLE
  540. gpointer
  541. mono_w32file_get_console_input (void)
  542. {
  543. g_unsupported_api ("GetStdHandle (STD_INPUT_HANDLE)");
  544. SetLastError (ERROR_NOT_SUPPORTED);
  545. return INVALID_HANDLE_VALUE;
  546. }
  547. gpointer
  548. mono_w32file_get_console_output (void)
  549. {
  550. g_unsupported_api ("GetStdHandle (STD_OUTPUT_HANDLE)");
  551. SetLastError (ERROR_NOT_SUPPORTED);
  552. return INVALID_HANDLE_VALUE;
  553. }
  554. gpointer
  555. mono_w32file_get_console_error (void)
  556. {
  557. g_unsupported_api ("GetStdHandle (STD_ERROR_HANDLE)");
  558. SetLastError (ERROR_NOT_SUPPORTED);
  559. return INVALID_HANDLE_VALUE;
  560. }
  561. #endif
  562. #if HAVE_API_SUPPORT_WIN32_GET_FILE_SIZE_EX
  563. gint64
  564. mono_w32file_get_file_size (HANDLE handle, gint32 *error)
  565. {
  566. LARGE_INTEGER length;
  567. MONO_ENTER_GC_SAFE;
  568. if (!GetFileSizeEx (handle, &length)) {
  569. *error=GetLastError ();
  570. length.QuadPart = INVALID_FILE_SIZE;
  571. }
  572. MONO_EXIT_GC_SAFE;
  573. return length.QuadPart;
  574. }
  575. #elif !HAVE_EXTERN_DEFINED_WIN32_GET_FILE_SIZE_EX
  576. gint64
  577. mono_w32file_get_file_size (HANDLE handle, gint32 *error)
  578. {
  579. g_unsupported_api ("GetFileSizeEx");
  580. *error = ERROR_NOT_SUPPORTED;
  581. SetLastError (ERROR_NOT_SUPPORTED);
  582. return 0;
  583. }
  584. #endif
  585. #if HAVE_API_SUPPORT_WIN32_GET_DRIVE_TYPE
  586. guint32
  587. mono_w32file_get_drive_type (const gunichar2 *root_path_name, gint32 root_path_name_length, MonoError *error)
  588. {
  589. guint32 res;
  590. MONO_ENTER_GC_SAFE;
  591. res = GetDriveTypeW (root_path_name);
  592. MONO_EXIT_GC_SAFE;
  593. return res;
  594. }
  595. #elif !HAVE_EXTERN_DEFINED_WIN32_GET_DRIVE_TYPE
  596. guint32
  597. mono_w32file_get_drive_type (const gunichar2 *root_path_name, gint32 root_path_name_length, MonoError *error)
  598. {
  599. g_unsupported_api ("GetDriveType");
  600. mono_error_set_not_supported (error, G_UNSUPPORTED_API, "GetDriveType");
  601. SetLastError (ERROR_NOT_SUPPORTED);
  602. return DRIVE_UNKNOWN;
  603. }
  604. #endif
  605. #if HAVE_API_SUPPORT_WIN32_GET_LOGICAL_DRIVE_STRINGS
  606. gint32
  607. mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf, MonoError *error)
  608. {
  609. gint32 res;
  610. MONO_ENTER_GC_SAFE;
  611. res = GetLogicalDriveStringsW (len, buf);
  612. MONO_EXIT_GC_SAFE;
  613. return res;
  614. }
  615. #elif !HAVE_EXTERN_DEFINED_WIN32_GET_LOGICAL_DRIVE_STRINGS
  616. gint32
  617. mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf, MonoError *error)
  618. {
  619. g_unsupported_api ("GetLogicalDriveStrings");
  620. mono_error_set_not_supported (error, G_UNSUPPORTED_API, "GetLogicalDriveStrings");
  621. SetLastError (ERROR_NOT_SUPPORTED);
  622. return 0;
  623. }
  624. #endif