public static string PtrToStringUnix(IntPtr p) { if (p == IntPtr.Zero) { return(null); } int num = (void *)(checked ((int)Stdlib.strlen(p))); return(new string((void *)p, 0, num, UnixEncoding.Instance)); }
private static int GetStringByteLength(IntPtr p, Encoding encoding) { Type type = encoding.GetType(); int num = -1; if (typeof(UTF8Encoding).IsAssignableFrom(type) || typeof(UTF7Encoding).IsAssignableFrom(type) || typeof(UnixEncoding).IsAssignableFrom(type) || typeof(ASCIIEncoding).IsAssignableFrom(type)) { num = (void *)(checked ((int)Stdlib.strlen(p))); } else { num = (!typeof(UnicodeEncoding).IsAssignableFrom(type) ? UnixMarshal.GetRandomBufferLength(p, encoding.GetMaxByteCount(1)) : UnixMarshal.GetInt16BufferLength(p)); } if (num == -1) { throw new NotSupportedException("Unable to determine native string buffer length"); } return(num); }
private static int GetRandomBufferLength(IntPtr p, int nullLength) { int num; int num1; int num2; switch (nullLength) { case 1: { return((void *)(checked ((int)Stdlib.strlen(p)))); } case 2: { return(UnixMarshal.GetInt16BufferLength(p)); } case 3: { num = 0; num1 = 0; do { num2 = num; num = num2 + 1; if (Marshal.ReadByte(p, num2) != 0) { num1 = 0; } else { num1++; } }while (num1 != nullLength); return(num); } case 4: { return(UnixMarshal.GetInt32BufferLength(p)); } default: { num = 0; num1 = 0; do { num2 = num; num = num2 + 1; if (Marshal.ReadByte(p, num2) != 0) { num1 = 0; } else { num1++; } }while (num1 != nullLength); return(num); } } }