summaryrefslogtreecommitdiff
path: root/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetComputerName.cs
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2019-01-17 20:07:12 -0500
committerStephen Toub <stoub@microsoft.com>2019-01-17 22:09:15 -0500
commit1e21dfc513b51b151d7c9b16f1e2a6a81c339d94 (patch)
tree98cd9247b0a90fcdd5ace9824aa1f28d3dda1733 /src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetComputerName.cs
parent8da1974d2d9ff47e45334f359199a3d50c8e0cbb (diff)
downloadcoreclr-1e21dfc513b51b151d7c9b16f1e2a6a81c339d94.tar.gz
coreclr-1e21dfc513b51b151d7c9b16f1e2a6a81c339d94.tar.bz2
coreclr-1e21dfc513b51b151d7c9b16f1e2a6a81c339d94.zip
Move Environment to shared CoreLib (dotnet/corefx#34654)
Rather than having Environment partially live in corefx and call into an EnvironmentAugments type in CoreLib that in turn calls into an Environment type in CoreLib, we're just moving Environment to live in CoreLib. To start that, this PR moves Environment and its dependencies from their current locations into the shared CoreLib. Those changes will mirror over to coreclr. After that, I'll fix it up to work in CoreLib. And once those changes are built and available back to corefx, I'll update System.Runtime.Extensions to just use the functionality from CoreLib and delete remaining unnecessary code from corefx. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Diffstat (limited to 'src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetComputerName.cs')
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetComputerName.cs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetComputerName.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetComputerName.cs
new file mode 100644
index 0000000000..34a26c180f
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetComputerName.cs
@@ -0,0 +1,28 @@
+// 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;
+
+internal partial class Interop
+{
+ internal partial class Kernel32
+ {
+ [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "GetComputerNameW")]
+ private static extern unsafe int GetComputerName(ref char lpBuffer, ref uint nSize);
+
+ // maximum length of the NETBIOS name (not including NULL)
+ private const int MAX_COMPUTERNAME_LENGTH = 15;
+
+ internal static unsafe string GetComputerName()
+ {
+ Span<char> buffer = stackalloc char[MAX_COMPUTERNAME_LENGTH + 1];
+ uint length = (uint)buffer.Length;
+
+ return GetComputerName(ref MemoryMarshal.GetReference(buffer), ref length) != 0 ?
+ buffer.Slice(0, (int)length).ToString() :
+ null;
+ }
+ }
+}