5 // Martin Baulig <martin.baulig@xamarin.com>
7 // Copyright (c) 2015 Xamarin Inc. (http://www.xamarin.com)
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 #if SECURITY_DEP && MONO_FEATURE_BTLS
30 using System.Runtime.InteropServices;
31 using System.Runtime.CompilerServices;
39 static class MonoBtlsError
41 [DllImport (MonoBtlsObject.BTLS_DYLIB)]
42 extern static int mono_btls_error_peek_error ();
44 [DllImport (MonoBtlsObject.BTLS_DYLIB)]
45 extern static int mono_btls_error_get_error ();
47 [DllImport (MonoBtlsObject.BTLS_DYLIB)]
48 extern static void mono_btls_error_clear_error ();
50 [DllImport (MonoBtlsObject.BTLS_DYLIB)]
51 extern static int mono_btls_error_peek_error_line (out IntPtr file, out int line);
53 [DllImport (MonoBtlsObject.BTLS_DYLIB)]
54 extern static int mono_btls_error_get_error_line (out IntPtr file, out int line);
56 [DllImport (MonoBtlsObject.BTLS_DYLIB)]
57 extern static void mono_btls_error_get_error_string_n (int error, IntPtr buf, int len);
59 public static int PeekError ()
61 return mono_btls_error_peek_error ();
64 public static int GetError ()
66 return mono_btls_error_get_error ();
69 public static void ClearError ()
71 mono_btls_error_clear_error ();
74 public static string GetErrorString (int error)
77 var buffer = Marshal.AllocHGlobal (size);
78 if (buffer == IntPtr.Zero)
79 throw new OutOfMemoryException ();
81 mono_btls_error_get_error_string_n (error, buffer, size);
82 return Marshal.PtrToStringAnsi (buffer);
84 Marshal.FreeHGlobal (buffer);
88 public static int PeekError (out string file, out int line)
91 var error = mono_btls_error_peek_error_line (out filePtr, out line);
92 if (filePtr != IntPtr.Zero)
93 file = Marshal.PtrToStringAnsi (filePtr);
99 public static int GetError (out string file, out int line)
102 var error = mono_btls_error_get_error_line (out filePtr, out line);
103 if (filePtr != IntPtr.Zero)
104 file = Marshal.PtrToStringAnsi (filePtr);