ecere: Initial Emscripten support
[sdk] / ecere / src / com / instance.c
index df9f68b..7ae555d 100644 (file)
@@ -1,3 +1,5 @@
+#define _Noreturn
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -248,7 +250,7 @@ bool Instance_LocateModule(const char * name, char * fileName)
    }
 #elif defined(__unix__)
    //File f = FileOpen("/proc/self/maps", read);
-   FILE * f;
+   FILE * f = null;
    char exeName[MAX_FILENAME];
    exeName[0] = 0;
 #if defined(__linux__)
@@ -325,7 +327,7 @@ bool Instance_LocateModule(const char * name, char * fileName)
       }
       fclose(f);
    }
-#if !defined(ECERE_NOFILE) && !defined(__linux__)
+#if !defined(ECERE_NOFILE) && !defined(__linux__) && !defined(__EMSCRIPTEN__)
    if(name && name[0])
    {
       // Couldn't locate libraries with /proc/curmap/map, attempt with ldd
@@ -491,7 +493,9 @@ void * Instance_Module_Load(const char * libLocation, const char * name, void **
       strcat(fileName, ".so");
 #endif
 
+#if !defined(__EMSCRIPTEN__)
    library = dlopen(fileName, RTLD_LAZY);
+#endif
    while(!library && attempts < sizeof(paths)/sizeof(paths[0]))
    {
       if(paths[attempts])
@@ -514,15 +518,19 @@ void * Instance_Module_Load(const char * libLocation, const char * name, void **
 #else
          strcat(fileName, ".so");
 #endif
+#if !defined(__EMSCRIPTEN__)
       library = dlopen(fileName, RTLD_LAZY);
+#endif
    }
 
    if(library)
    {
       *Load = dlsym(library, "__ecereDll_Load");
       *Unload = dlsym(library, "__ecereDll_Unload");
+#if !defined(__EMSCRIPTEN__)
       if(!*Load)
          dlclose(library);
+#endif
    }
 #elif defined(__APPLE__)
    if(libLocation || strchr(name, '/'))
@@ -568,7 +576,7 @@ void Instance_Module_Free(void * library)
 #if defined(__WIN32__)
    if(library)
       FreeLibrary(library);
-#elif defined(__unix__) || defined(__APPLE__)
+#elif (defined(__unix__) || defined(__APPLE__)) && !defined(__EMSCRIPTEN__)
    if(library)
       dlclose(library);
 #endif