1f049bd7954bd5a865a8428862343f8a61a3b3f7
[platform/upstream/coreclr.git] / src / System.Private.CoreLib / shared / System / Runtime / InteropServices / Marshal.Unix.cs
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 using System.Diagnostics;
6 using System.Text;
7
8 namespace System.Runtime.InteropServices
9 {
10     public static partial class Marshal
11     {
12         private static int GetSystemMaxDBCSCharSize() => 3;
13
14         private static bool IsWin32Atom(IntPtr ptr) => false;
15
16         internal static unsafe int StringToAnsiString(string s, byte* buffer, int bufferLength, bool bestFit = false, bool throwOnUnmappableChar = false)
17         {
18             Debug.Assert(bufferLength >= (s.Length + 1) * SystemMaxDBCSCharSize, "Insufficient buffer length passed to StringToAnsiString");
19
20             int convertedBytes;
21
22             fixed (char* pChar = s)
23             {
24                 convertedBytes = Encoding.UTF8.GetBytes(pChar, s.Length, buffer, bufferLength);
25             }
26
27             buffer[convertedBytes] = 0;
28
29             return convertedBytes;
30         }
31     }
32 }