diff options
author | Jan Kotas <jkotas@microsoft.com> | 2018-01-20 18:18:07 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-20 18:18:07 -0800 |
commit | 1ea580bab8adc060a88c87e29790b8fa7d91c098 (patch) | |
tree | 972213d7b73930d527b780024a93d7debbf94ad9 /src | |
parent | 7f4fbdbbaa6f9874678efa7a2cf7463502480fe6 (diff) | |
download | coreclr-1ea580bab8adc060a88c87e29790b8fa7d91c098.tar.gz coreclr-1ea580bab8adc060a88c87e29790b8fa7d91c098.tar.bz2 coreclr-1ea580bab8adc060a88c87e29790b8fa7d91c098.zip |
Define Interop.Kernel32.MAX_PATH (#15952)
* Define Interop.Kernel32.MAX_PATH
For consistency with CoreFX and coding conventions.
Diffstat (limited to 'src')
8 files changed, 30 insertions, 24 deletions
diff --git a/src/mscorlib/shared/Interop/Windows/Kernel32/Interop.MAX_PATH.cs b/src/mscorlib/shared/Interop/Windows/Kernel32/Interop.MAX_PATH.cs new file mode 100644 index 0000000000..f7fa32669b --- /dev/null +++ b/src/mscorlib/shared/Interop/Windows/Kernel32/Interop.MAX_PATH.cs @@ -0,0 +1,11 @@ +// 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. + +internal partial class Interop +{ + internal partial class Kernel32 + { + internal const int MAX_PATH = 260; + } +} diff --git a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems index e49edfd367..9819da7a28 100644 --- a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems @@ -643,6 +643,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetTempPathW.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.Globalization.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" /> <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.LockFile.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.MAX_PATH.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.OutputDebugString.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.ReadFile_SafeHandle_IntPtr.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.ReadFile_SafeHandle_NativeOverlapped.cs" /> diff --git a/src/mscorlib/shared/System/IO/Path.Windows.cs b/src/mscorlib/shared/System/IO/Path.Windows.cs index 5d92d3b490..c5cb0d80de 100644 --- a/src/mscorlib/shared/System/IO/Path.Windows.cs +++ b/src/mscorlib/shared/System/IO/Path.Windows.cs @@ -27,10 +27,6 @@ namespace System.IO (char)31 }; - // The max total path is 260, and the max individual component length is 255. - // For example, D:\<256 char file name> isn't legal, even though it's under 260 chars. - internal const int MaxPath = 260; - // Expands the given path to a fully qualified path. public static string GetFullPath(string path) { @@ -93,8 +89,8 @@ namespace System.IO public static string GetTempPath() { - StringBuilder sb = StringBuilderCache.Acquire(MaxPath); - uint r = Interop.Kernel32.GetTempPathW(MaxPath, sb); + StringBuilder sb = StringBuilderCache.Acquire(Interop.Kernel32.MAX_PATH); + uint r = Interop.Kernel32.GetTempPathW(Interop.Kernel32.MAX_PATH, sb); if (r == 0) throw Win32Marshal.GetExceptionForLastWin32Error(); return GetFullPath(StringBuilderCache.GetStringAndRelease(sb)); @@ -106,7 +102,7 @@ namespace System.IO { string path = GetTempPath(); - StringBuilder sb = StringBuilderCache.Acquire(MaxPath); + StringBuilder sb = StringBuilderCache.Acquire(Interop.Kernel32.MAX_PATH); uint r = Interop.Kernel32.GetTempFileNameW(path, "tmp", 0, sb); if (r == 0) throw Win32Marshal.GetExceptionForLastWin32Error(); diff --git a/src/mscorlib/shared/System/ReadOnlySpan.cs b/src/mscorlib/shared/System/ReadOnlySpan.cs index 1854df40fa..4e6339a74c 100644 --- a/src/mscorlib/shared/System/ReadOnlySpan.cs +++ b/src/mscorlib/shared/System/ReadOnlySpan.cs @@ -165,7 +165,6 @@ namespace System /// <exception cref="System.IndexOutOfRangeException"> /// Thrown when index less than 0 or index greater than or equal to Length /// </exception> - public ref readonly T this[int index] { #if PROJECTN diff --git a/src/mscorlib/src/System/Threading/EventWaitHandle.cs b/src/mscorlib/src/System/Threading/EventWaitHandle.cs index d2ed335682..38326de0c1 100644 --- a/src/mscorlib/src/System/Threading/EventWaitHandle.cs +++ b/src/mscorlib/src/System/Threading/EventWaitHandle.cs @@ -50,9 +50,9 @@ namespace System.Threading #if PLATFORM_UNIX throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives); #else - if (System.IO.Path.MaxPath < name.Length) + if (Interop.Kernel32.MAX_PATH < name.Length) { - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Path.MaxPath), nameof(name)); + throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Interop.Kernel32.MAX_PATH), nameof(name)); } #endif } @@ -98,9 +98,9 @@ namespace System.Threading #if PLATFORM_UNIX throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives); #else - if (System.IO.Path.MaxPath < name.Length) + if (Interop.Kernel32.MAX_PATH < name.Length) { - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Path.MaxPath), nameof(name)); + throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Interop.Kernel32.MAX_PATH), nameof(name)); } #endif } @@ -184,9 +184,9 @@ namespace System.Threading throw new ArgumentException(SR.Argument_EmptyName, nameof(name)); } - if (null != name && System.IO.Path.MaxPath < name.Length) + if (null != name && Interop.Kernel32.MAX_PATH < name.Length) { - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Path.MaxPath), nameof(name)); + throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Interop.Kernel32.MAX_PATH), nameof(name)); } diff --git a/src/mscorlib/src/System/Threading/Mutex.cs b/src/mscorlib/src/System/Threading/Mutex.cs index 864dcb8056..6b2b930d90 100644 --- a/src/mscorlib/src/System/Threading/Mutex.cs +++ b/src/mscorlib/src/System/Threading/Mutex.cs @@ -90,9 +90,9 @@ namespace System.Threading #if !PLATFORM_UNIX private static void VerifyNameForCreate(string name) { - if (name != null && (Path.MaxPath < name.Length)) + if (name != null && (Interop.Kernel32.MAX_PATH < name.Length)) { - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Path.MaxPath), nameof(name)); + throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Interop.Kernel32.MAX_PATH), nameof(name)); } } #endif @@ -100,7 +100,7 @@ namespace System.Threading private void CreateMutexCore(bool initiallyOwned, string name, out bool createdNew) { #if !PLATFORM_UNIX - Debug.Assert(name == null || name.Length <= Path.MaxPath); + Debug.Assert(name == null || name.Length <= Interop.Kernel32.MAX_PATH); #endif uint mutexFlags = initiallyOwned ? Win32Native.CREATE_MUTEX_INITIAL_OWNER : 0; diff --git a/src/mscorlib/src/System/Threading/Semaphore.cs b/src/mscorlib/src/System/Threading/Semaphore.cs index 1cf4ac531f..012d0e516d 100644 --- a/src/mscorlib/src/System/Threading/Semaphore.cs +++ b/src/mscorlib/src/System/Threading/Semaphore.cs @@ -93,8 +93,8 @@ namespace System.Threading #if PLATFORM_UNIX throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives); #else - if (name.Length > Path.MaxPath) - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Path.MaxPath), nameof(name)); + if (name.Length > Interop.Kernel32.MAX_PATH) + throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Interop.Kernel32.MAX_PATH), nameof(name)); #endif } @@ -135,8 +135,8 @@ namespace System.Threading throw new ArgumentNullException(nameof(name), SR.ArgumentNull_WithParamName); if (name.Length == 0) throw new ArgumentException(SR.Argument_EmptyName, nameof(name)); - if (name.Length > Path.MaxPath) - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Path.MaxPath), nameof(name)); + if (name.Length > Interop.Kernel32.MAX_PATH) + throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Interop.Kernel32.MAX_PATH), nameof(name)); //Pass false to OpenSemaphore to prevent inheritedHandles SafeWaitHandle myHandle = Win32Native.OpenSemaphore(AccessRights, false, name); diff --git a/src/mscorlib/src/System/TimeZoneInfo.Win32.cs b/src/mscorlib/src/System/TimeZoneInfo.Win32.cs index 08fc921751..21e74a7925 100644 --- a/src/mscorlib/src/System/TimeZoneInfo.Win32.cs +++ b/src/mscorlib/src/System/TimeZoneInfo.Win32.cs @@ -818,9 +818,8 @@ namespace System try { - StringBuilder fileMuiPath = StringBuilderCache.Acquire(Path.MaxPath); - fileMuiPath.Length = Path.MaxPath; - int fileMuiPathLength = Path.MaxPath; + StringBuilder fileMuiPath = StringBuilderCache.Acquire(Interop.Kernel32.MAX_PATH); + int fileMuiPathLength = Interop.Kernel32.MAX_PATH; int languageLength = 0; long enumerator = 0; |