X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FUtility.cs;h=9081b011dc210a1e631ee5470021b9354f4e6221;hb=b177bc98ac5b0e8b59f00becffadda7ceeb32553;hp=f8b4ffd8982857d55b65f603f839efb666cfa6fd;hpb=94d2753047cff1e9223e42736884e4d51348b45a;p=catta diff --git a/avahi-sharp/Utility.cs b/avahi-sharp/Utility.cs index f8b4ffd..9081b01 100644 --- a/avahi-sharp/Utility.cs +++ b/avahi-sharp/Utility.cs @@ -24,7 +24,9 @@ using System.Net; using System.Text; using System.Runtime.InteropServices; using Mono.Unix; +using Mono.Unix.Native; +using Stdlib = Mono.Unix.Native.Stdlib; namespace Avahi { @@ -60,12 +62,20 @@ namespace Avahi return ret; } - public static IntPtr StringToPtr (string str) + public static byte[] StringToBytes (string str) + { + if (str == null) + return null; + + return Encoding.UTF8.GetBytes (str + "\0"); // lame. + } + + private static IntPtr StringToPtr (string str) { if (str == null) return IntPtr.Zero; - byte[] bytes = Encoding.UTF8.GetBytes (str); + byte[] bytes = Utility.StringToBytes (str); IntPtr buf = Stdlib.malloc ((uint) bytes.Length + 1); Marshal.Copy (bytes, 0, buf, bytes.Length); Marshal.WriteByte (buf, bytes.Length, 0);