public static void SplitServiceName(string service, out string name, out string type, out string domain) { int len = 1024; IntPtr namePtr = Stdlib.malloc((ulong)len); IntPtr typePtr = Stdlib.malloc((ulong)len); IntPtr domainPtr = Stdlib.malloc((ulong)len); int ret = avahi_service_name_split(Utility.StringToBytes(service), namePtr, len, typePtr, len, domainPtr, len); if (ret < 0) { Utility.Free(namePtr); Utility.Free(typePtr); Utility.Free(domainPtr); name = null; type = null; domain = null; return; } name = Utility.PtrToString(namePtr); type = Utility.PtrToString(typePtr); domain = Utility.PtrToString(domainPtr); Utility.Free(namePtr); Utility.Free(typePtr); Utility.Free(domainPtr); }
public static IntPtr AddressToPtr(IPAddress address) { IntPtr straddr = Utility.StringToPtr(address.ToString()); IntPtr addrPtr = Stdlib.malloc(32); avahi_address_parse(straddr, Protocol.Unspecified, addrPtr); Utility.Free(straddr); return(addrPtr); }
public static IPAddress PtrToAddress(IntPtr ptr) { IPAddress address = null; if (ptr != IntPtr.Zero) { IntPtr buf = Stdlib.malloc(256); IntPtr addrPtr = avahi_address_snprint(buf, 256, ptr); address = IPAddress.Parse(Utility.PtrToString(addrPtr)); Utility.Free(addrPtr); } return(address); }
private static IntPtr StringToPtr(string str) { if (str == null) { return(IntPtr.Zero); } 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); return(buf); }
private string GetDump() { if (FilePosition.FilePositionDumpSize <= 0) { return("internal error"); } StringBuilder stringBuilder = new StringBuilder(FilePosition.FilePositionDumpSize + 1); if (Stdlib.DumpFilePosition(stringBuilder, this.Handle, FilePosition.FilePositionDumpSize + 1) <= 0) { return("internal error dumping fpos_t"); } return(stringBuilder.ToString()); }
public static string tmpnam() { string str; object tmpnamLock = Stdlib.tmpnam_lock; Monitor.Enter(tmpnamLock); try { str = UnixMarshal.PtrToString(Stdlib.sys_tmpnam(null)); } finally { Monitor.Exit(tmpnamLock); } return(str); }
public static string strerror(Errno errnum) { string str; int num = NativeConvert.FromErrno(errnum); object strerrorLock = Stdlib.strerror_lock; Monitor.Enter(strerrorLock); try { str = UnixMarshal.PtrToString(Stdlib.sys_strerror(num)); } finally { Monitor.Exit(strerrorLock); } return(str); }
public static string JoinServiceName(string name, string type, string domain) { int len = 4 * (name.Length + type.Length + domain.Length) + 4; IntPtr buf = Stdlib.malloc((ulong)len); int ret = avahi_service_name_join(buf, len, Utility.StringToBytes(name), Utility.StringToBytes(type), Utility.StringToBytes(domain)); if (ret < 0) { Utility.Free(buf); return(null); // FIXME, should throw exception } string service = Utility.PtrToString(buf); Utility.Free(buf); return(service); }
public static int snprintf(StringBuilder s, string message) { return(Stdlib.sys_snprintf(s, (ulong)s.Capacity, "%s", message)); }
public static unsafe int setvbuf(IntPtr stream, byte *buf, int mode, ulong size) { return(Stdlib.setvbuf(stream, (IntPtr)buf, mode, size)); }
public static int fprintf(IntPtr stream, string message) { return(Stdlib.sys_fprintf(stream, "%s", message)); }
public static unsafe ulong fwrite(void *ptr, ulong size, ulong nmemb, IntPtr stream) { return(Stdlib.fwrite((IntPtr)ptr, size, nmemb, stream)); }
public static int raise(RealTimeSignum rts) { return(Stdlib.sys_raise(NativeConvert.FromRealTimeSignum(rts))); }
public static int raise(Signum sig) { return(Stdlib.sys_raise(NativeConvert.FromSignum(sig))); }
public static int printf(string message) { return(Stdlib.sys_printf("%s", message)); }
public static int perror(string s) { return(Stdlib.perror(s, Marshal.GetLastWin32Error())); }
public static string getenv(string name) { return(UnixMarshal.PtrToString(Stdlib.sys_getenv(name))); }
public static ulong fwrite(byte[] ptr, IntPtr stream) { return(Stdlib.fwrite(ptr, (ulong)1, (ulong)((int)ptr.Length), stream)); }
static FilePosition() { FilePosition.FilePositionDumpSize = Stdlib.DumpFilePosition(null, new HandleRef(null, IntPtr.Zero), 0); }
public static int fseek(IntPtr stream, long offset, SeekFlags origin) { return(Stdlib.sys_fseek(stream, offset, NativeConvert.FromSeekFlags(origin))); }
public static unsafe int setbuf(IntPtr stream, byte *buf) { return(Stdlib.setbuf(stream, (IntPtr)buf)); }
public static int fsetpos(IntPtr stream, FilePosition pos) { return(Stdlib.sys_fsetpos(stream, pos.Handle)); }
public static void Free(IntPtr ptr) { Stdlib.free(ptr); }
protected static void SetLastError(Errno error) { Stdlib.SetLastError(NativeConvert.FromErrno(error)); }
public void InvokeSignalHandler(int signum) { Stdlib.InvokeSignalHandler(signum, handler); }
public static int SetSignalAction(Signum signal, SignalAction action) { return(Stdlib.SetSignalAction(NativeConvert.FromSignum(signal), action)); }
public static int SetSignalAction(RealTimeSignum rts, SignalAction action) { return(Stdlib.SetSignalAction(NativeConvert.FromRealTimeSignum(rts), action)); }
public static StringBuilder fgets(StringBuilder sb, IntPtr stream) { return(Stdlib.fgets(sb, sb.Capacity, stream)); }