You've already forked linux-packaging-mono
Imported Upstream version 5.14.0.78
Former-commit-id: 3494343bcc9ddb42b36b82dd9ae7b69e85e0229f
This commit is contained in:
parent
74b74abd9f
commit
19234507ba
25
external/corert/src/System.Private.CoreLib/shared/Internal/IO/File.Unix.cs
vendored
Normal file
25
external/corert/src/System.Private.CoreLib/shared/Internal/IO/File.Unix.cs
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace Internal.IO
|
||||
{
|
||||
internal static partial class File
|
||||
{
|
||||
internal static bool InternalExists(string fullPath)
|
||||
{
|
||||
Interop.Sys.FileStatus fileinfo;
|
||||
|
||||
// First use stat, as we want to follow symlinks. If that fails, it could be because the symlink
|
||||
// is broken, we don't have permissions, etc., in which case fall back to using LStat to evaluate
|
||||
// based on the symlink itself.
|
||||
if (Interop.Sys.Stat(fullPath, out fileinfo) < 0 &&
|
||||
Interop.Sys.LStat(fullPath, out fileinfo) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((fileinfo.Mode & Interop.Sys.FileTypes.S_IFMT) != Interop.Sys.FileTypes.S_IFDIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
77
external/corert/src/System.Private.CoreLib/shared/Internal/IO/File.Windows.cs
vendored
Normal file
77
external/corert/src/System.Private.CoreLib/shared/Internal/IO/File.Windows.cs
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.Win32;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Internal.IO
|
||||
{
|
||||
internal static partial class File
|
||||
{
|
||||
internal static bool InternalExists(string fullPath)
|
||||
{
|
||||
Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = new Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA();
|
||||
int errorCode = FillAttributeInfo(fullPath, ref data, returnErrorOnNotFound: true);
|
||||
|
||||
return (errorCode == 0) && (data.dwFileAttributes != -1)
|
||||
&& ((data.dwFileAttributes & Interop.Kernel32.FileAttributes.FILE_ATTRIBUTE_DIRECTORY) == 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns 0 on success, otherwise a Win32 error code. Note that
|
||||
/// classes should use -1 as the uninitialized state for dataInitialized.
|
||||
/// </summary>
|
||||
/// <param name="returnErrorOnNotFound">Return the error code for not found errors?</param>
|
||||
internal static int FillAttributeInfo(string path, ref Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data, bool returnErrorOnNotFound)
|
||||
{
|
||||
int errorCode = Interop.Errors.ERROR_SUCCESS;
|
||||
|
||||
using (DisableMediaInsertionPrompt.Create())
|
||||
{
|
||||
if (!Interop.Kernel32.GetFileAttributesEx(path, Interop.Kernel32.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, ref data))
|
||||
{
|
||||
errorCode = Marshal.GetLastWin32Error();
|
||||
if (errorCode == Interop.Errors.ERROR_ACCESS_DENIED)
|
||||
{
|
||||
// Files that are marked for deletion will not let you GetFileAttributes,
|
||||
// ERROR_ACCESS_DENIED is given back without filling out the data struct.
|
||||
// FindFirstFile, however, will. Historically we always gave back attributes
|
||||
// for marked-for-deletion files.
|
||||
|
||||
var findData = new Interop.Kernel32.WIN32_FIND_DATA();
|
||||
using (SafeFindHandle handle = Interop.Kernel32.FindFirstFile(path, ref findData))
|
||||
{
|
||||
if (handle.IsInvalid)
|
||||
{
|
||||
errorCode = Marshal.GetLastWin32Error();
|
||||
}
|
||||
else
|
||||
{
|
||||
errorCode = Interop.Errors.ERROR_SUCCESS;
|
||||
data.PopulateFrom(ref findData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCode != Interop.Errors.ERROR_SUCCESS && !returnErrorOnNotFound)
|
||||
{
|
||||
switch (errorCode)
|
||||
{
|
||||
case Interop.Errors.ERROR_FILE_NOT_FOUND:
|
||||
case Interop.Errors.ERROR_PATH_NOT_FOUND:
|
||||
case Interop.Errors.ERROR_NOT_READY: // Removable media not ready
|
||||
// Return default value for backward compatibility
|
||||
data.dwFileAttributes = -1;
|
||||
return Interop.Errors.ERROR_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,24 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Security;
|
||||
using System.IO;
|
||||
|
||||
namespace System.IO
|
||||
namespace Internal.IO
|
||||
{
|
||||
internal static partial class InternalFile
|
||||
//
|
||||
// Subsetted clone of System.IO.File for internal runtime use.
|
||||
// Keep in sync with https://github.com/dotnet/corefx/tree/master/src/System.IO.FileSystem.
|
||||
//
|
||||
internal static partial class File
|
||||
{
|
||||
// Tests if a file exists. The result is true if the file
|
||||
// given by the specified path exists; otherwise, the result is
|
||||
// false. Note that if path describes a directory,
|
||||
// Exists will return true.
|
||||
public static bool Exists(String path)
|
||||
public static bool Exists(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -43,5 +49,29 @@ namespace System.IO
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static byte[] ReadAllBytes(string path)
|
||||
{
|
||||
// bufferSize == 1 used to avoid unnecessary buffer in FileStream
|
||||
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 1))
|
||||
{
|
||||
long fileLength = fs.Length;
|
||||
if (fileLength > int.MaxValue)
|
||||
throw new IOException(SR.IO_FileTooLong2GB);
|
||||
|
||||
int index = 0;
|
||||
int count = (int)fileLength;
|
||||
byte[] bytes = new byte[count];
|
||||
while (count > 0)
|
||||
{
|
||||
int n = fs.Read(bytes, index, count);
|
||||
if (n == 0)
|
||||
throw Error.GetEndOfFile();
|
||||
index += n;
|
||||
count -= n;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,6 +168,46 @@ namespace Internal.Runtime.CompilerServices
|
||||
// ret
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the memory address referenced by <paramref name="left"/> is greater than
|
||||
/// the memory address referenced by <paramref name="right"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This check is conceptually similar to "(void*)(&left) > (void*)(&right)".
|
||||
/// </remarks>
|
||||
[Intrinsic]
|
||||
[NonVersionable]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsAddressGreaterThan<T>(ref T left, ref T right)
|
||||
{
|
||||
throw new PlatformNotSupportedException();
|
||||
|
||||
// ldarg.0
|
||||
// ldarg.1
|
||||
// cgt.un
|
||||
// ret
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the memory address referenced by <paramref name="left"/> is less than
|
||||
/// the memory address referenced by <paramref name="right"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This check is conceptually similar to "(void*)(&left) < (void*)(&right)".
|
||||
/// </remarks>
|
||||
[Intrinsic]
|
||||
[NonVersionable]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsAddressLessThan<T>(ref T left, ref T right)
|
||||
{
|
||||
throw new PlatformNotSupportedException();
|
||||
|
||||
// ldarg.0
|
||||
// ldarg.1
|
||||
// clt.un
|
||||
// ret
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a block of memory at the given location with a given initial value
|
||||
/// without assuming architecture dependent alignment of the address.
|
||||
|
||||
@@ -6,7 +6,7 @@ internal static partial class Interop
|
||||
{
|
||||
internal static partial class Libraries
|
||||
{
|
||||
internal const string GlobalizationInterop = "System.Globalization.Native";
|
||||
internal const string GlobalizationNative = "System.Globalization.Native";
|
||||
internal const string SystemNative = "System.Native";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,25 +9,25 @@ using System.Text;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class GlobalizationInterop
|
||||
internal static partial class Globalization
|
||||
{
|
||||
internal delegate void EnumCalendarInfoCallback(
|
||||
[MarshalAs(UnmanagedType.LPWStr)] string calendarString,
|
||||
IntPtr context);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendars")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendars")]
|
||||
internal static extern int GetCalendars(string localeName, CalendarId[] calendars, int calendarsCapacity);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendarInfo")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendarInfo")]
|
||||
internal static extern ResultCode GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType calendarDataType, [Out] StringBuilder result, int resultCapacity);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EnumCalendarInfo")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EnumCalendarInfo")]
|
||||
internal static extern bool EnumCalendarInfo(EnumCalendarInfoCallback callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, EntryPoint = "GlobalizationNative_GetLatestJapaneseEra")]
|
||||
[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLatestJapaneseEra")]
|
||||
internal static extern int GetLatestJapaneseEra();
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, EntryPoint = "GlobalizationNative_GetJapaneseEraStartDate")]
|
||||
[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetJapaneseEraStartDate")]
|
||||
internal static extern bool GetJapaneseEraStartDate(int era, out int startYear, out int startMonth, out int startDay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,15 +9,15 @@ using System.Text;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class GlobalizationInterop
|
||||
internal static partial class Globalization
|
||||
{
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCase")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCase")]
|
||||
internal unsafe static extern void ChangeCase(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseInvariant")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseInvariant")]
|
||||
internal unsafe static extern void ChangeCaseInvariant(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseTurkish")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseTurkish")]
|
||||
internal unsafe static extern void ChangeCaseTurkish(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,41 +9,53 @@ using System.Security;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class GlobalizationInterop
|
||||
internal static partial class Globalization
|
||||
{
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetSortHandle")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetSortHandle")]
|
||||
internal unsafe static extern ResultCode GetSortHandle(byte[] localeName, out SafeSortHandle sortHandle);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CloseSortHandle")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CloseSortHandle")]
|
||||
internal unsafe static extern void CloseSortHandle(IntPtr handle);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CompareString")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CompareString")]
|
||||
internal unsafe static extern int CompareString(SafeSortHandle sortHandle, char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len, CompareOptions options);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOf")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOf")]
|
||||
internal unsafe static extern int IndexOf(SafeSortHandle sortHandle, string target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr);
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOf")]
|
||||
internal unsafe static extern int IndexOf(SafeSortHandle sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_LastIndexOf")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_LastIndexOf")]
|
||||
internal unsafe static extern int LastIndexOf(SafeSortHandle sortHandle, string target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOfOrdinalIgnoreCase")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOfOrdinalIgnoreCase")]
|
||||
internal unsafe static extern int IndexOfOrdinalIgnoreCase(string target, int cwTargetLength, char* pSource, int cwSourceLength, bool findLast);
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOfOrdinalIgnoreCase")]
|
||||
internal unsafe static extern int IndexOfOrdinalIgnoreCase(char* target, int cwTargetLength, char* pSource, int cwSourceLength, bool findLast);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_StartsWith")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_StartsWith")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal unsafe static extern bool StartsWith(SafeSortHandle sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options);
|
||||
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EndsWith")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal unsafe static extern bool EndsWith(SafeSortHandle sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options);
|
||||
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_StartsWith")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal unsafe static extern bool StartsWith(SafeSortHandle sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EndsWith")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EndsWith")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal unsafe static extern bool EndsWith(SafeSortHandle sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetSortKey")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetSortKey")]
|
||||
internal unsafe static extern int GetSortKey(SafeSortHandle sortHandle, string str, int strLength, byte* sortKey, int sortKeyLength, CompareOptions options);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CompareStringOrdinalIgnoreCase")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CompareStringOrdinalIgnoreCase")]
|
||||
internal unsafe static extern int CompareStringOrdinalIgnoreCase(char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, EntryPoint = "GlobalizationNative_GetSortVersion")]
|
||||
[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortVersion")]
|
||||
internal static extern int GetSortVersion(SafeSortHandle sortHandle);
|
||||
|
||||
internal class SafeSortHandle : SafeHandle
|
||||
|
||||
@@ -8,9 +8,9 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class GlobalizationInterop
|
||||
internal static partial class Globalization
|
||||
{
|
||||
[DllImport(Libraries.GlobalizationInterop, EntryPoint = "GlobalizationNative_LoadICU")]
|
||||
[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_LoadICU")]
|
||||
internal static extern int LoadICU();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@ using System.Runtime.InteropServices;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class GlobalizationInterop
|
||||
internal static partial class Globalization
|
||||
{
|
||||
internal const int AllowUnassigned = 0x1;
|
||||
internal const int UseStd3AsciiRules = 0x2;
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToAscii")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToAscii")]
|
||||
internal static unsafe extern int ToAscii(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToUnicode")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToUnicode")]
|
||||
internal static unsafe extern int ToUnicode(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,33 +8,33 @@ using System.Text;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class GlobalizationInterop
|
||||
internal static partial class Globalization
|
||||
{
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleName")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleName")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal unsafe static extern bool GetLocaleName(string localeName, [Out] StringBuilder value, int valueLength);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoString")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoString")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal unsafe static extern bool GetLocaleInfoString(string localeName, uint localeStringData, [Out] StringBuilder value, int valueLength);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetDefaultLocaleName")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetDefaultLocaleName")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal unsafe static extern bool GetDefaultLocaleName([Out] StringBuilder value, int valueLength);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleTimeFormat")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleTimeFormat")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal unsafe static extern bool GetLocaleTimeFormat(string localeName, bool shortFormat, [Out] StringBuilder value, int valueLength);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoInt")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoInt")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal unsafe static extern bool GetLocaleInfoInt(string localeName, uint localeNumberData, ref int value);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoGroupingSizes")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoGroupingSizes")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal unsafe static extern bool GetLocaleInfoGroupingSizes(string localeName, uint localeGroupingData, ref int primaryGroupSize, ref int secondaryGroupSize);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocales")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocales")]
|
||||
internal unsafe static extern int GetLocales([Out] Char[] value, int valueLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ using System.Text;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class GlobalizationInterop
|
||||
internal static partial class Globalization
|
||||
{
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IsNormalized")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IsNormalized")]
|
||||
internal static extern int IsNormalized(NormalizationForm normalizationForm, string src, int srcLen);
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_NormalizeString")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_NormalizeString")]
|
||||
internal static extern int NormalizeString(NormalizationForm normalizationForm, string src, int srcLen, [Out] char[] dstBuffer, int dstBufferCapacity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class GlobalizationInterop
|
||||
internal static partial class Globalization
|
||||
{
|
||||
// needs to be kept in sync with ResultCode in System.Globalization.Native
|
||||
internal enum ResultCode
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Text;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class GlobalizationInterop
|
||||
internal static partial class Globalization
|
||||
{
|
||||
// needs to be kept in sync with TimeZoneDisplayNameType in System.Globalization.Native
|
||||
internal enum TimeZoneDisplayNameType
|
||||
@@ -17,7 +17,7 @@ internal static partial class Interop
|
||||
DaylightSavings = 2,
|
||||
}
|
||||
|
||||
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetTimeZoneDisplayName")]
|
||||
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetTimeZoneDisplayName")]
|
||||
internal static extern ResultCode GetTimeZoneDisplayName(
|
||||
string localeName,
|
||||
string timeZoneId,
|
||||
|
||||
@@ -13,7 +13,7 @@ internal static partial class Interop
|
||||
/// increasing buffer until the size is big enough.
|
||||
/// </summary>
|
||||
internal static bool CallStringMethod<TArg1, TArg2, TArg3>(
|
||||
Func<TArg1, TArg2, TArg3, StringBuilder, GlobalizationInterop.ResultCode> interopCall,
|
||||
Func<TArg1, TArg2, TArg3, StringBuilder, Interop.Globalization.ResultCode> interopCall,
|
||||
TArg1 arg1,
|
||||
TArg2 arg2,
|
||||
TArg3 arg3,
|
||||
@@ -26,14 +26,14 @@ internal static partial class Interop
|
||||
|
||||
for (int i = 0; i < maxDoubleAttempts; i++)
|
||||
{
|
||||
GlobalizationInterop.ResultCode resultCode = interopCall(arg1, arg2, arg3, stringBuilder);
|
||||
Interop.Globalization.ResultCode resultCode = interopCall(arg1, arg2, arg3, stringBuilder);
|
||||
|
||||
if (resultCode == GlobalizationInterop.ResultCode.Success)
|
||||
if (resultCode == Interop.Globalization.ResultCode.Success)
|
||||
{
|
||||
result = StringBuilderCache.GetStringAndRelease(stringBuilder);
|
||||
return true;
|
||||
}
|
||||
else if (resultCode == GlobalizationInterop.ResultCode.InsufficentBuffer)
|
||||
else if (resultCode == Interop.Globalization.ResultCode.InsufficentBuffer)
|
||||
{
|
||||
// increase the string size and loop
|
||||
stringBuilder.EnsureCapacity(stringBuilder.Capacity * 2);
|
||||
|
||||
@@ -9,8 +9,6 @@ internal static partial class Interop
|
||||
{
|
||||
internal static partial class Sys
|
||||
{
|
||||
internal static int DEFAULT_PC_NAME_MAX = 255;
|
||||
|
||||
internal enum PathConfName : int
|
||||
{
|
||||
PC_LINK_MAX = 1,
|
||||
|
||||
102
external/corert/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ReadDir.cs
vendored
Normal file
102
external/corert/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ReadDir.cs
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class Sys
|
||||
{
|
||||
private static readonly int s_readBufferSize = GetReadDirRBufferSize();
|
||||
|
||||
internal enum NodeType : int
|
||||
{
|
||||
DT_UNKNOWN = 0,
|
||||
DT_FIFO = 1,
|
||||
DT_CHR = 2,
|
||||
DT_DIR = 4,
|
||||
DT_BLK = 6,
|
||||
DT_REG = 8,
|
||||
DT_LNK = 10,
|
||||
DT_SOCK = 12,
|
||||
DT_WHT = 14
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private unsafe struct InternalDirectoryEntry
|
||||
{
|
||||
internal IntPtr Name;
|
||||
internal int NameLength;
|
||||
internal NodeType InodeType;
|
||||
}
|
||||
|
||||
internal struct DirectoryEntry
|
||||
{
|
||||
internal NodeType InodeType;
|
||||
internal string InodeName;
|
||||
}
|
||||
|
||||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_OpenDir", SetLastError = true)]
|
||||
internal static extern Microsoft.Win32.SafeHandles.SafeDirectoryHandle OpenDir(string path);
|
||||
|
||||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetReadDirRBufferSize", SetLastError = false)]
|
||||
internal static extern int GetReadDirRBufferSize();
|
||||
|
||||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadDirR", SetLastError = false)]
|
||||
private static extern unsafe int ReadDirR(IntPtr dir, byte* buffer, int bufferSize, out InternalDirectoryEntry outputEntry);
|
||||
|
||||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CloseDir", SetLastError = true)]
|
||||
internal static extern int CloseDir(IntPtr dir);
|
||||
|
||||
// The calling pattern for ReadDir is described in src/Native/System.Native/pal_readdir.cpp
|
||||
internal static int ReadDir(SafeDirectoryHandle dir, out DirectoryEntry outputEntry)
|
||||
{
|
||||
bool addedRef = false;
|
||||
try
|
||||
{
|
||||
// We avoid a native string copy into InternalDirectoryEntry.
|
||||
// - If the platform suppors reading into a buffer, the data is read directly into the buffer. The
|
||||
// data can be read as long as the buffer is valid.
|
||||
// - If the platform does not support reading into a buffer, the information returned in
|
||||
// InternalDirectoryEntry points to native memory owned by the SafeDirectoryHandle. The data is only
|
||||
// valid until the next call to CloseDir/ReadDir. We extend the reference until we have copied all data
|
||||
// to ensure it does not become invalid by a CloseDir; and we copy the data so our caller does not
|
||||
// use the native memory held by the SafeDirectoryHandle.
|
||||
dir.DangerousAddRef(ref addedRef);
|
||||
|
||||
unsafe
|
||||
{
|
||||
// s_readBufferSize is zero when the native implementation does not support reading into a buffer.
|
||||
byte* buffer = stackalloc byte[s_readBufferSize];
|
||||
InternalDirectoryEntry temp;
|
||||
int ret = ReadDirR(dir.DangerousGetHandle(), buffer, s_readBufferSize, out temp);
|
||||
// We copy data into DirectoryEntry to ensure there are no dangling references.
|
||||
outputEntry = ret == 0 ?
|
||||
new DirectoryEntry() { InodeName = GetDirectoryEntryName(temp), InodeType = temp.InodeType } :
|
||||
default(DirectoryEntry);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (addedRef)
|
||||
{
|
||||
dir.DangerousRelease();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static unsafe string GetDirectoryEntryName(InternalDirectoryEntry dirEnt)
|
||||
{
|
||||
if (dirEnt.NameLength == -1)
|
||||
return Marshal.PtrToStringAnsi(dirEnt.Name);
|
||||
else
|
||||
return Marshal.PtrToStringAnsi(dirEnt.Name, dirEnt.NameLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,13 @@ internal static partial class Interop
|
||||
internal uint Gid;
|
||||
internal long Size;
|
||||
internal long ATime;
|
||||
internal long ATimeNsec;
|
||||
internal long MTime;
|
||||
internal long MTimeNsec;
|
||||
internal long CTime;
|
||||
internal long CTimeNsec;
|
||||
internal long BirthTime;
|
||||
internal long BirthTimeNsec;
|
||||
internal long Dev;
|
||||
internal long Ino;
|
||||
}
|
||||
@@ -49,13 +53,13 @@ internal static partial class Interop
|
||||
HasBirthTime = 1,
|
||||
}
|
||||
|
||||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FStat", SetLastError = true)]
|
||||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FStat2", SetLastError = true)]
|
||||
internal static extern int FStat(SafeFileHandle fd, out FileStatus output);
|
||||
|
||||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Stat", SetLastError = true)]
|
||||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Stat2", SetLastError = true)]
|
||||
internal static extern int Stat(string path, out FileStatus output);
|
||||
|
||||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LStat", SetLastError = true)]
|
||||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LStat2", SetLastError = true)]
|
||||
internal static extern int LStat(string path, out FileStatus output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ internal partial class Interop
|
||||
internal const int ERROR_NO_UNICODE_TRANSLATION = 0x459;
|
||||
internal const int ERROR_NOT_FOUND = 0x490;
|
||||
internal const int ERROR_BAD_IMPERSONATION_LEVEL = 0x542;
|
||||
internal const int ERROR_NO_SYSTEM_RESOURCES = 0x5AA;
|
||||
internal const int E_FILENOTFOUND = unchecked((int)0x80070002);
|
||||
internal const int ERROR_TIMEOUT = 0x000005B4;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ internal partial class Interop
|
||||
|
||||
internal struct WIN32_FILE_ATTRIBUTE_DATA
|
||||
{
|
||||
internal int fileAttributes;
|
||||
internal int dwFileAttributes;
|
||||
internal uint ftCreationTimeLow;
|
||||
internal uint ftCreationTimeHigh;
|
||||
internal uint ftLastAccessTimeLow;
|
||||
@@ -44,7 +44,7 @@ internal partial class Interop
|
||||
internal void PopulateFrom(ref WIN32_FIND_DATA findData)
|
||||
{
|
||||
// Copy the information to data
|
||||
fileAttributes = (int)findData.dwFileAttributes;
|
||||
dwFileAttributes = (int)findData.dwFileAttributes;
|
||||
ftCreationTimeLow = findData.ftCreationTime.dwLowDateTime;
|
||||
ftCreationTimeHigh = findData.ftCreationTime.dwHighDateTime;
|
||||
ftLastAccessTimeLow = findData.ftLastAccessTime.dwLowDateTime;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user