Define Interop.Kernel32.MAX_PATH (#15952)
authorJan Kotas <jkotas@microsoft.com>
Sun, 21 Jan 2018 02:18:07 +0000 (18:18 -0800)
committerGitHub <noreply@github.com>
Sun, 21 Jan 2018 02:18:07 +0000 (18:18 -0800)
* Define Interop.Kernel32.MAX_PATH

For consistency with CoreFX and coding conventions.

src/mscorlib/shared/Interop/Windows/Kernel32/Interop.MAX_PATH.cs [new file with mode: 0644]
src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
src/mscorlib/shared/System/IO/Path.Windows.cs
src/mscorlib/shared/System/ReadOnlySpan.cs
src/mscorlib/src/System/Threading/EventWaitHandle.cs
src/mscorlib/src/System/Threading/Mutex.cs
src/mscorlib/src/System/Threading/Semaphore.cs
src/mscorlib/src/System/TimeZoneInfo.Win32.cs

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 (file)
index 0000000..f7fa326
--- /dev/null
@@ -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;
+    }
+}
index e49edfd..9819da7 100644 (file)
     <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" />
index 5d92d3b..c5cb0d8 100644 (file)
@@ -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();
index 1854df4..4e6339a 100644 (file)
@@ -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
index d2ed335..38326de 100644 (file)
@@ -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));
             }
 
 
index 864dcb8..6b2b930 100644 (file)
@@ -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;
index 1cf4ac5..012d0e5 100644 (file)
@@ -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);
index 08fc921..21e74a7 100644 (file)
@@ -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;