Przeglądaj źródła

Added dynamic library handling.

bkaradzic 12 lat temu
rodzic
commit
e88e3a3e2a
1 zmienionych plików z 46 dodań i 0 usunięć
  1. 46 0
      include/bx/os.h

+ 46 - 0
include/bx/os.h

@@ -15,6 +15,7 @@
 #	else
 #		include <time.h> // nanosleep
 #	endif // BX_PLATFORM_NACL
+#	include <dlfcn.h>
 #endif // BX_PLATFORM_
 
 namespace bx
@@ -41,6 +42,51 @@ namespace bx
 #endif // BX_PLATFORM_
 	}
 
+	inline void* dlopen(const char* _filePath)
+	{
+#if BX_PLATFORM_WINDOWS
+		return (void*)LoadLibraryA(_filePath);
+#else
+		return ::dlopen(_filePath, RTLD_LOCAL|RTLD_LAZY);
+#endif // BX_PLATFORM_
+	}
+
+	inline void dlclose(void* _handle)
+	{
+#if BX_PLATFORM_WINDOWS
+		FreeLibrary( (HMODULE)_handle);
+#else
+		::dlclose(_lib);
+#endif // BX_PLATFORM_
+	}
+
+	inline void* dlsym(void* _handle, const char* _symbol)
+	{
+#if BX_PLATFORM_WINDOWS
+		return (void*)GetProcAddress( (HMODULE)_handle, _symbol);
+#else
+		return dlsym(_handle, _symbol);
+#endif // BX_PLATFORM_
+	}
+
+	inline void setenv(const char* _name, const char* _value)
+	{
+#if BX_PLATFORM_WINDOWS
+		SetEnvironmentVariableA(_name, _value);
+#else
+		setenv(_name, _value, 1);
+#endif // BX_PLATFORM_
+	}
+
+	inline void unsetenv(const char* _name)
+	{
+#if BX_PLATFORM_WINDOWS
+		SetEnvironmentVariableA(_name, NULL);
+#else
+		unsetenv(_name);
+#endif // BX_PLATFORM_
+	}
+
 } // namespace bx
 
 #endif // __BX_OS_H__