示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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());
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
 public static int snprintf(StringBuilder s, string message)
 {
     return(Stdlib.sys_snprintf(s, (ulong)s.Capacity, "%s", message));
 }
示例#10
0
 public static unsafe int setvbuf(IntPtr stream, byte *buf, int mode, ulong size)
 {
     return(Stdlib.setvbuf(stream, (IntPtr)buf, mode, size));
 }
示例#11
0
 public static int fprintf(IntPtr stream, string message)
 {
     return(Stdlib.sys_fprintf(stream, "%s", message));
 }
示例#12
0
 public static unsafe ulong fwrite(void *ptr, ulong size, ulong nmemb, IntPtr stream)
 {
     return(Stdlib.fwrite((IntPtr)ptr, size, nmemb, stream));
 }
示例#13
0
 public static int raise(RealTimeSignum rts)
 {
     return(Stdlib.sys_raise(NativeConvert.FromRealTimeSignum(rts)));
 }
示例#14
0
 public static int raise(Signum sig)
 {
     return(Stdlib.sys_raise(NativeConvert.FromSignum(sig)));
 }
示例#15
0
 public static int printf(string message)
 {
     return(Stdlib.sys_printf("%s", message));
 }
示例#16
0
 public static int perror(string s)
 {
     return(Stdlib.perror(s, Marshal.GetLastWin32Error()));
 }
示例#17
0
 public static string getenv(string name)
 {
     return(UnixMarshal.PtrToString(Stdlib.sys_getenv(name)));
 }
示例#18
0
 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);
 }
示例#20
0
 public static int fseek(IntPtr stream, long offset, SeekFlags origin)
 {
     return(Stdlib.sys_fseek(stream, offset, NativeConvert.FromSeekFlags(origin)));
 }
示例#21
0
 public static unsafe int setbuf(IntPtr stream, byte *buf)
 {
     return(Stdlib.setbuf(stream, (IntPtr)buf));
 }
示例#22
0
 public static int fsetpos(IntPtr stream, FilePosition pos)
 {
     return(Stdlib.sys_fsetpos(stream, pos.Handle));
 }
示例#23
0
 public static void Free(IntPtr ptr)
 {
     Stdlib.free(ptr);
 }
示例#24
0
 protected static void SetLastError(Errno error)
 {
     Stdlib.SetLastError(NativeConvert.FromErrno(error));
 }
示例#25
0
 public void InvokeSignalHandler(int signum)
 {
     Stdlib.InvokeSignalHandler(signum, handler);
 }
示例#26
0
 public static int SetSignalAction(Signum signal, SignalAction action)
 {
     return(Stdlib.SetSignalAction(NativeConvert.FromSignum(signal), action));
 }
示例#27
0
 public static int SetSignalAction(RealTimeSignum rts, SignalAction action)
 {
     return(Stdlib.SetSignalAction(NativeConvert.FromRealTimeSignum(rts), action));
 }
示例#28
0
 public static StringBuilder fgets(StringBuilder sb, IntPtr stream)
 {
     return(Stdlib.fgets(sb, sb.Capacity, stream));
 }