Subversion Repositories Tewi

Rev

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

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