summaryrefslogtreecommitdiff
path: root/src/ElmSharp/Interop/Interop.Libdl.cs
diff options
context:
space:
mode:
authorWonYoung Choi <wy80.choi@samsung.com>2017-07-21 10:52:25 +0900
committerWonYoung Choi <wy80.choi@samsung.com>2017-07-21 10:52:25 +0900
commit9551e95f9270c4f076ce9b10a57f4b7db7bf04bd (patch)
tree233b134d53b7bbadd250014fb27d7a512883152d /src/ElmSharp/Interop/Interop.Libdl.cs
parent0b8fdbbe5a40fdd31d1c73a7a5f920332bb7ab24 (diff)
downloadmeta-package-9551e95f9270c4f076ce9b10a57f4b7db7bf04bd.tar.gz
meta-package-9551e95f9270c4f076ce9b10a57f4b7db7bf04bd.tar.bz2
meta-package-9551e95f9270c4f076ce9b10a57f4b7db7bf04bd.zip
Initial unified Tizen .NET modulestizenfx
Change-Id: I56353c0f86e2eeb665eec3eb92f695da69fa9afe
Diffstat (limited to 'src/ElmSharp/Interop/Interop.Libdl.cs')
-rw-r--r--src/ElmSharp/Interop/Interop.Libdl.cs60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/ElmSharp/Interop/Interop.Libdl.cs b/src/ElmSharp/Interop/Interop.Libdl.cs
new file mode 100644
index 0000000..4f233f8
--- /dev/null
+++ b/src/ElmSharp/Interop/Interop.Libdl.cs
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Libdl
+ {
+ private const int RTLD_NOW = 2;
+
+ [DllImport(Libraries.Libdl)]
+ private static extern IntPtr dlopen(string filename, int flags);
+
+ [DllImport(Libraries.Libdl)]
+ private static extern int dlclose(IntPtr handle);
+
+ [DllImport(Libraries.Libdl)]
+ private static extern IntPtr dlsym(IntPtr handle, string symbol);
+
+ [DllImport(Libraries.Libdl)]
+ private static extern IntPtr dlerror();
+
+ internal static IntPtr LoadLibrary(string filename)
+ {
+ return dlopen(filename, RTLD_NOW);
+ }
+
+ internal static void FreeLibrary(IntPtr handle)
+ {
+ dlclose(handle);
+ }
+
+ internal static IntPtr GetProcAddress(IntPtr handle, string name)
+ {
+ dlerror();
+ var res = dlsym(handle, name);
+ var errPtr = dlerror();
+ if (errPtr != IntPtr.Zero)
+ {
+ throw new Exception("dlsym : " + Marshal.PtrToStringAnsi(errPtr));
+ }
+ return res;
+ }
+ }
+}