Replace PrintF with Console.WriteLine and cleanups (dotnet/corefx#41540)
authorAdeel Mujahid <adeelbm@outlook.com>
Fri, 4 Oct 2019 18:48:15 +0000 (21:48 +0300)
committerStephen Toub <stoub@microsoft.com>
Fri, 4 Oct 2019 18:48:15 +0000 (14:48 -0400)
* Replace PrintF with Console.WriteLine and cleanups

* PR feedback: simplify WriteLine arguments

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

src/libraries/Common/src/Microsoft/Win32/SafeHandles/SafeX509Handles.Unix.cs
src/libraries/Native/Unix/System.Native/pal_string.c
src/libraries/Native/Unix/System.Native/pal_string.h
src/libraries/System.Net.Http/src/System.Net.Http.csproj
src/libraries/System.Net.Security/src/System.Net.Security.csproj
src/libraries/System.Security.Cryptography.X509Certificates/src/System.Security.Cryptography.X509Certificates.csproj

index 60d3e12..984ad13 100644 (file)
@@ -21,9 +21,7 @@ namespace Microsoft.Win32.SafeHandles
         {
             if (s_captureTrace)
             {
-                Interop.Sys.PrintF(
-                    "%s\n\n",
-                    $"0x{handle.ToInt64():x} {_stacktrace?.ToString() ?? "no stacktrace..."}");
+                Console.WriteLine($"0x{handle.ToInt64():x} {_stacktrace?.ToString() ?? "no stacktrace..."}");
             }
         }
 #endif
index 6562816..48d2e84 100644 (file)
@@ -2,14 +2,12 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-#include "pal_config.h"
 #include "pal_string.h"
 #include "pal_utilities.h"
 
 #include <assert.h>
 #include <stdarg.h>
 #include <stdio.h>
-#include <string.h>
 
 int32_t SystemNative_SNPrintF(char* string, int32_t size, const char* format, ...)
 {
@@ -26,12 +24,3 @@ int32_t SystemNative_SNPrintF(char* string, int32_t size, const char* format, ..
     va_end(arguments);
     return result;
 }
-
-int32_t SystemNative_PrintF(const char* format, ...)
-{
-    va_list arguments;
-    va_start(arguments, format);
-    int result = vprintf(format, arguments);
-    va_end(arguments);
-    return result;
-}
index 6b1c3b1..380c75e 100644 (file)
  * On failure, returns a negative value.
  */
 DLLEXPORT int32_t SystemNative_SNPrintF(char* string, int32_t size, const char* format, ...);
-
-/**
- * printf is difficult to represent in C# due to the argument list, so the C# PInvoke
- * layer will have multiple overloads pointing to this function.
- *
- * Returns the number of characters written to the output stream on success; otherwise, returns
- * a negative number and errno and ferror are both set.
- */
-DLLEXPORT int32_t SystemNative_PrintF(const char* format, ...);
index 9c35bf0..00202df 100644 (file)
     <Compile Include="$(CommonPath)\Interop\Unix\System.Native\Interop.Poll.cs">
       <Link>Common\Interop\Unix\libc\Interop.Poll.cs</Link>
     </Compile>
-    <Compile Include="$(CommonPath)\Interop\Unix\System.Native\Interop.PrintF.cs">
-      <Link>Common\Interop\Unix\libc\Interop.PrintF.cs</Link>
-    </Compile>
     <Compile Include="$(CommonPath)\CoreLib\Interop\Unix\System.Native\Interop.Read.cs">
       <Link>Common\Interop\Unix\libc\Interop.Read.cs</Link>
     </Compile>
     <Reference Include="System.IO.Compression.Brotli" />
   </ItemGroup>
   <ItemGroup Condition="'$(TargetsUnix)' == 'true'">
+    <Reference Include="System.Console" Condition="'$(ConfigurationGroup)' == 'Debug'" />
     <Reference Include="System.Diagnostics.StackTrace" />
     <Reference Include="System.IO.FileSystem" />
     <Reference Include="System.Security.Cryptography.Algorithms" />
index 8228956..e41f160 100644 (file)
     <Compile Include="$(CommonPath)\CoreLib\Interop\Unix\Interop.Errors.cs">
       <Link>Common\CoreLib\Interop\Unix\Interop.Errors.cs</Link>
     </Compile>
-    <Compile Include="$(CommonPath)\Interop\Unix\System.Native\Interop.PrintF.cs">
-      <Link>Common\Interop\Unix\System.Native\Interop.PrintF.cs</Link>
-    </Compile>
     <Compile Include="$(CommonPath)\Interop\Unix\System.Net.Security.Native\Interop.Initialization.cs">
       <Link>Common\Interop\Unix\System.Net.Security.Native\Interop.Initialization.cs</Link>
     </Compile>
     <Reference Include="System.Threading.ThreadPool" />
   </ItemGroup>
   <ItemGroup Condition="'$(TargetsUnix)' == 'true'">
+    <Reference Include="System.Console" Condition="'$(ConfigurationGroup)' == 'Debug'" />
     <Reference Include="System.Diagnostics.StackTrace" />
     <Reference Include="System.Security.Cryptography.Algorithms" />
     <Reference Include="System.Security.Cryptography.OpenSsl" />
index b73b107..56efaeb 100644 (file)
     <Compile Include="Microsoft\Win32\SafeHandles\SafePasswordHandle.Unix.cs" />
   </ItemGroup>
   <ItemGroup Condition=" '$(TargetsUnix)' == 'true' AND '$(TargetsOSX)' != 'true' ">
-    <Compile Include="$(CommonPath)\Interop\Unix\System.Native\Interop.PrintF.cs">
-      <Link>Common\Interop\Unix\System.Native\Interop.PrintF.cs</Link>
-    </Compile>
     <AsnXml Include="System\Security\Cryptography\X509Certificates\Asn1\DistributionPointAsn.xml" />
     <Compile Include="System\Security\Cryptography\X509Certificates\Asn1\DistributionPointAsn.xml.cs">
       <DependentUpon>System\Security\Cryptography\X509Certificates\Asn1\DistributionPointAsn.xml</DependentUpon>
     <Reference Include="System.Diagnostics.StackTrace" />
     <Reference Include="System.Security.Cryptography.OpenSsl" />
   </ItemGroup>
+  <ItemGroup Condition="'$(TargetsUnix)' == 'true'">
+    <Reference Include="System.Console" Condition="'$(ConfigurationGroup)' == 'Debug'" />
+  </ItemGroup>
   <ItemGroup>
     <None Include="@(AsnXml)" /> 
   </ItemGroup>