Fix CPINFOEXW definition (dotnet/corefx#37131)
authorJan Kotas <jkotas@microsoft.com>
Wed, 24 Apr 2019 15:46:42 +0000 (08:46 -0700)
committerStephen Toub <stoub@microsoft.com>
Wed, 24 Apr 2019 15:46:42 +0000 (11:46 -0400)
* Fix CPINFOEXW definition

* Unify MAX_PATH definition and switch to use it for GetCPInfoEx

Commit migrated from https://github.com/dotnet/corefx/commit/24efeca2cb7e8a83125ecdbc62c95040fddabdf2

src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetCPInfoEx.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.MaxLengths.cs
src/libraries/Microsoft.IO.Redist/src/Microsoft.IO.Redist.csproj
src/libraries/System.Console/src/System.Console.csproj
src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj
src/libraries/System.IO.FileSystem/src/System.IO.FileSystem.csproj
src/libraries/System.Text.Encoding.CodePages/src/System.Text.Encoding.CodePages.csproj

index b9218bf..33bd08f 100644 (file)
@@ -9,7 +9,7 @@ internal partial class Interop
     internal partial class Kernel32
     {
         [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "GetCPInfoExW")]
-        private extern static unsafe int GetCPInfoExW(uint CodePage, uint dwFlags, CPINFOEXW* lpCPInfoEx);
+        private extern static unsafe Interop.BOOL GetCPInfoExW(uint CodePage, uint dwFlags, CPINFOEXW* lpCPInfoEx);
 
         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
         private unsafe struct CPINFOEXW
@@ -19,14 +19,14 @@ internal partial class Interop
             internal fixed byte LeadByte[12];
             internal char UnicodeDefaultChar;
             internal uint CodePage;
-            internal fixed byte CodePageName[260];
+            internal fixed char CodePageName[MAX_PATH];
         }
 
         internal static unsafe int GetLeadByteRanges(int codePage, byte[] leadByteRanges)
         {
             int count = 0;
             CPINFOEXW cpInfo;
-            if (GetCPInfoExW((uint) codePage, 0, &cpInfo) != 0)
+            if (GetCPInfoExW((uint)codePage, 0, &cpInfo) != BOOL.FALSE)
             {
                 // we don't care about the last 2 bytes as those are nulls
                 for (int i=0; i<10 && leadByteRanges[i] != 0; i+=2)
@@ -44,7 +44,7 @@ internal partial class Interop
             // Note: GetACP is not available in the Windows Store Profile, but calling
             // GetCPInfoEx with the value CP_ACP (0) yields the same result.
             CPINFOEXW cpInfo;
-            if (GetCPInfoExW(CP_ACP, 0, &cpInfo) != 0)
+            if (GetCPInfoExW(CP_ACP, 0, &cpInfo) != BOOL.FALSE)
             {
                 codePage = (int)cpInfo.CodePage;
                 return true;
index dc9d621..4f7b588 100644 (file)
@@ -6,8 +6,6 @@ internal partial class Interop
 {
     internal partial class Kernel32
     {
-        internal const int MAX_PATH = 260;
-
         internal const int CREDUI_MAX_USERNAME_LENGTH = 513;
     }
 }
index 295b777..8e03fc4 100644 (file)
     <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.FILE_INFO_BY_HANDLE_CLASS.cs">
       <Link>Common\Interop\Windows\Interop.FILE_INFO_BY_HANDLE_CLASS.cs</Link>
     </Compile>
-    <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.MaxLengths.cs">
-      <Link>Common\Interop\Windows\Interop.MaxLengths.cs</Link>
+    <Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.MAX_PATH.cs">
+      <Link>Common\CoreLib\Interop\Windows\Interop.MAX_PATH.cs</Link>
     </Compile>
     <Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.FileAttributes.cs">
       <Link>Common\Interop\Windows\Interop.FileAttributes.cs</Link>
index ad9d4ec..3296b24 100644 (file)
@@ -39,6 +39,9 @@
     <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.GetCPInfoEx.cs">
       <Link>Common\Interop\Windows\Interop.GetCPInfoEx.cs</Link>
     </Compile>
+    <Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.MAX_PATH.cs">
+      <Link>Common\CoreLib\Interop\Windows\Interop.MAX_PATH.cs</Link>
+    </Compile>
     <Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
       <Link>Common\Interop\Windows\Interop.Libraries.cs</Link>
     </Compile>
index dcec78c..68732d0 100644 (file)
     <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.GetCPInfoEx.cs">
       <Link>Common\Interop\Windows\Kernel32\Interop.GetCPInfoEx.cs</Link>
     </Compile>
+    <Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.MAX_PATH.cs">
+      <Link>Common\CoreLib\Interop\Windows\Interop.MAX_PATH.cs</Link>
+    </Compile>
     <Compile Include="Microsoft\Win32\SafeHandles\SafeProcessHandle.Windows.cs" />
     <Compile Include="Microsoft\Win32\SafeHandles\SafeThreadHandle.cs" />
     <Compile Include="System\Diagnostics\PerformanceCounterLib.cs" />
index 14d7470..ae5cdb0 100644 (file)
     <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.GetDiskFreeSpaceEx.cs">
       <Link>Common\Interop\Windows\Interop.GetDiskFreeSpaceEx.cs</Link>
     </Compile>
-    <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.MaxLengths.cs">
-      <Link>Common\Interop\Windows\Interop.MaxLengths.cs</Link>
+    <Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.MAX_PATH.cs">
+      <Link>Common\CoreLib\Interop\Windows\Interop.MAX_PATH.cs</Link>
     </Compile>
     <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.SetVolumeLabel.cs">
       <Link>Common\Interop\Windows\Interop.SetVolumeLabel.cs</Link>
     </Compile>
     <Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.SetThreadErrorMode.cs">
-      <Link>Common\CoreLibInterop\Windows\Interop.SetThreadErrorMode.cs</Link>
+      <Link>Common\CoreLib\Interop\Windows\Interop.SetThreadErrorMode.cs</Link>
     </Compile>
     <Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.SecurityOptions.cs">
       <Link>Common\Interop\Windows\Interop.SecurityOptions.cs</Link>
index 539e47f..bf6a88d 100644 (file)
     <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.GenericOperations.cs">
       <Link>Common\Interop\Windows\Interop.GenericOperations.cs</Link>
     </Compile>
-    <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.MaxLengths.cs">
-      <Link>Common\Interop\Windows\Interop.MaxLengths.cs</Link>
+    <Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.MAX_PATH.cs">
+      <Link>Common\CoreLib\Interop\Windows\Interop.MAX_PATH.cs</Link>
     </Compile>
     <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.WIN32_FIND_DATA.cs">
       <Link>Common\Interop\Windows\Interop.WIN32_FIND_DATA.cs</Link>
index 560705f..cd60bb2 100644 (file)
     <Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
       <Link>Common\Interop\Windows\Interop.Libraries.cs</Link>
     </Compile>
+    <Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Interop.BOOL.cs">
+      <Link>Common\CoreLib\Interop\Windows\Interop.BOOL.cs</Link>
+    </Compile>
     <Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.GetCPInfoEx.cs">
       <Link>Common\Interop\Windows\Interop.GetCPInfoEx.cs</Link>
     </Compile>
+    <Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.MAX_PATH.cs">
+      <Link>Common\CoreLib\Interop\Windows\Interop.MAX_PATH.cs</Link>
+    </Compile>
     <Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.WideCharToMultiByte.cs">
       <Link>Common\CoreLib\Interop\Windows\Kernel32\Interop.WideCharToMultiByte.cs</Link>
     </Compile>