[2020-02][System.Native] Handle ReadDir EINTR (#21029)
[mono-project.git] / mcs / class / corlib / corefx / Interop.ReadDir.Mono.cs
blobb5fb5495d64ce8f31c7698ce6e572a380af1c59f
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 using System;
6 using System.Runtime.InteropServices;
8 internal static partial class Interop
10 internal static partial class Sys
12 [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_OpenDir", SetLastError = true)]
13 internal static extern IntPtr OpenDir_native(string path);
15 [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadDirR", SetLastError = false)]
16 internal static extern unsafe int ReadDirR_native(IntPtr dir, byte* buffer, int bufferSize, out DirectoryEntry outputEntry);
18 [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CloseDir", SetLastError = true)]
19 internal static extern int CloseDir_native(IntPtr dir);
21 internal static IntPtr OpenDir (string path) {
22 IntPtr result;
23 do {
24 result = OpenDir_native (path);
25 } while (result == IntPtr.Zero && Marshal.GetLastWin32Error () == (int) Interop.Error.EINTR);
26 return result;
29 internal static int CloseDir (IntPtr dir) {
30 int result;
31 do {
32 result = CloseDir_native (dir);
33 } while (result < 0 && Marshal.GetLastWin32Error () == (int) Interop.Error.EINTR);
34 return result;
37 internal static unsafe int ReadDirR (IntPtr dir, byte* buffer, int bufferSize, out DirectoryEntry outputEntry) {
38 int result;
39 do {
40 result = ReadDirR_native (dir, buffer, bufferSize, out outputEntry);
41 } while (result == (int) Interop.Error.EINTR);
42 return result;