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