[EflSharp] Introduce EflSharp project (#749)
[platform/core/csapi/tizenfx.git] / internals / src / EflSharp / EflSharp / NativeModule_Unix.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 namespace Efl { namespace Eo {
5
6 public partial class NativeModule
7 {
8     public const int RTLD_NOW = 0x002;
9     // Currently we are using GLOBAL due to issues
10     // with the way evas modules are built.
11     public const int RTLD_GLOBAL = 0x100;
12
13     [DllImport(efl.Libs.Libdl)]
14     public static extern IntPtr dlopen(string fileName, int flag);
15     [DllImport(efl.Libs.Libdl)]
16     public static extern int dlclose(IntPtr handle);
17
18     public static void UnloadLibrary(IntPtr handle)
19     {
20         dlclose(handle);
21     }
22
23     public static IntPtr LoadLibrary(string filename)
24     {
25         Eina.Log.Debug($"Loading library {filename}");
26         var r = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
27         if (r == IntPtr.Zero)
28         {
29             r = dlopen("lib" + filename, RTLD_NOW | RTLD_GLOBAL);
30             if (r == IntPtr.Zero)
31             {
32                 r = dlopen(filename + ".so", RTLD_NOW | RTLD_GLOBAL);
33                 if (r == IntPtr.Zero)
34                 {
35                     r = dlopen("lib" + filename + ".so", RTLD_NOW | RTLD_GLOBAL);
36                 }
37             }
38         }
39         return r;
40     }
41 }
42
43
44
45
46 } }