[BTLS]: Improve error handling. (#4317)
[mono.git] / mcs / class / System / Mono.Btls / MonoBtlsError.cs
index 5e61bcf04634b91e2c80d4c93668ddd9ebae6034..8371bdd0a63c16d0f6fd86bc54946e5662bfbe24 100644 (file)
@@ -47,6 +47,12 @@ namespace Mono.Btls
                [DllImport (MonoBtlsObject.BTLS_DYLIB)]
                extern static void mono_btls_error_clear_error ();
 
+               [DllImport (MonoBtlsObject.BTLS_DYLIB)]
+               extern static int mono_btls_error_peek_error_line (out IntPtr file, out int line);
+
+               [DllImport (MonoBtlsObject.BTLS_DYLIB)]
+               extern static int mono_btls_error_get_error_line (out IntPtr file, out int line);
+
                [DllImport (MonoBtlsObject.BTLS_DYLIB)]
                extern static void mono_btls_error_get_error_string_n (int error, IntPtr buf, int len);
 
@@ -78,6 +84,28 @@ namespace Mono.Btls
                                Marshal.FreeHGlobal (buffer);
                        }
                }
+
+               public static int PeekError (out string file, out int line)
+               {
+                       IntPtr filePtr;
+                       var error = mono_btls_error_peek_error_line (out filePtr, out line);
+                       if (filePtr != IntPtr.Zero)
+                               file = Marshal.PtrToStringAnsi (filePtr);
+                       else
+                               file = null;
+                       return error;
+               }
+
+               public static int GetError (out string file, out int line)
+               {
+                       IntPtr filePtr;
+                       var error = mono_btls_error_get_error_line (out filePtr, out line);
+                       if (filePtr != IntPtr.Zero)
+                               file = Marshal.PtrToStringAnsi (filePtr);
+                       else
+                               file = null;
+                       return error;
+               }
        }
 }
 #endif