Subversion Repositories Tewi

Rev

Rev 189 | Rev 215 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 189 Rev 212
Line 1... Line 1...
1
/* $Id: module.c 189 2024-09-29 00:37:00Z nishi $ */
1
/* $Id: module.c 212 2024-10-02 17:44:55Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "tw_module.h"
5
#include "tw_module.h"
6
 
6
 
Line 8... Line 8...
8
 
8
 
9
#include <cm_string.h>
9
#include <cm_string.h>
10
#include <cm_log.h>
10
#include <cm_log.h>
11
 
11
 
12
#include <string.h>
12
#include <string.h>
13
#include <unistd.h>
-
 
14
#include <stdlib.h>
13
#include <stdlib.h>
-
 
14
#ifndef _MSC_VER
-
 
15
#include <unistd.h>
-
 
16
#endif
15
 
17
 
16
extern struct tw_config config;
18
extern struct tw_config config;
17
 
19
 
18
#if defined(_PSP) || defined(__PPU__) || defined(__ps2sdk__)
20
#if defined(_PSP) || defined(__PPU__) || defined(__ps2sdk__)
19
void* tw_module_load(const char* path) { return NULL; }
21
void* tw_module_load(const char* path) { return NULL; }
Line 22... Line 24...
22
 
24
 
23
int tw_module_init(void* mod) { return 1; }
25
int tw_module_init(void* mod) { return 1; }
24
 
26
 
25
#else
27
#else
26
 
28
 
27
#ifdef __MINGW32__
29
#if defined(__MINGW32__) || defined(_MSC_VER)
28
#include <windows.h>
30
#include <windows.h>
29
#else
31
#else
30
#include <dlfcn.h>
32
#include <dlfcn.h>
31
#endif
33
#endif
32
 
34
 
33
void* tw_module_load(const char* path) {
35
void* tw_module_load(const char* path) {
34
	char* p = getcwd(NULL, 0);
36
	char* p = getcwd(NULL, 0);
35
	chdir(config.server_root);
-
 
36
	void* lib;
37
	void* lib;
-
 
38
	chdir(config.server_root);
37
#ifdef __MINGW32__
39
#if defined(__MINGW32__) || defined(_MSC_VER)
38
	lib = LoadLibraryA(path);
40
	lib = LoadLibraryA(path);
39
#else
41
#else
40
	lib = dlopen(path, RTLD_LAZY);
42
	lib = dlopen(path, RTLD_LAZY);
41
#endif
43
#endif
42
	if(lib == NULL) {
44
	if(lib == NULL) {
Line 46... Line 48...
46
	free(p);
48
	free(p);
47
	return lib;
49
	return lib;
48
}
50
}
49
 
51
 
50
void* tw_module_symbol(void* mod, const char* sym) {
52
void* tw_module_symbol(void* mod, const char* sym) {
51
#ifdef __MINGW32__
53
#if defined(__MINGW32__) || defined(_MSC_VER)
52
	return GetProcAddress(mod, sym);
54
	return GetProcAddress(mod, sym);
53
#else
55
#else
54
	return dlsym(mod, sym);
56
	return dlsym(mod, sym);
55
#endif
57
#endif
56
}
58
}