1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
--- glide64_0_7_ME/Ini.cpp.old 2005-01-07 15:50:22.232410116 -0800
+++ glide64_0_7_ME/Ini.cpp 2005-01-07 15:58:03.491450616 -0800
@@ -49,37 +49,42 @@
#include <stdlib.h>
#endif // _WIN32
+#include <features.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include <limits.h>
+
BOOL INI_Open ()
{
// Get the path of the dll, ex: C:\Games\Project64\Plugin\Glide64.dll
- char path[256];
-#ifdef _WIN32
- GetModuleFileName (hInstance, path, 256);
-#else // _WIN32
- int n = readlink("/proc/self/exe", path, 256);
- if (n == -1) strcpy(path, "./");
-#endif // _WIN32
-
- // Find the previous backslash
- int i;
- for (i=strlen(path)-1; i>0; i--)
+ char path[PATH_MAX];
+
+
+#ifdef __USE_GNU
+ Dl_info info;
+ void *addr = (void *)INI_Open;
+ //__asm__( "movl %%eip, %%eax" : "=a"(addr) );
+ if (dladdr( addr, &info ) != 0)
{
-#ifdef _WIN32
- if (path[i] == '\\')
-#else // _WIN32
- if (path[i] == '/')
-#endif // _WIN32
- break;
+ strncpy( path, info.dli_fname, PATH_MAX );
+ *(strrchr( path, '/' )) = '\0';
}
- if (path == 0) return FALSE;
- path[i+1] = 0;
-
-#ifndef _WIN32
- strcat(path, "plugins/");
-#endif // _WIN32
-
- strcat (path, "Glide64.ini");
-
+ else
+ {
+ fprintf( stderr, "(WW) Couldn't get path of .so, trying to get emulator's path\n" );
+#endif // __USE_GNU
+ if (readlink( "/proc/self/exe", path, PATH_MAX ) == -1)
+ {
+ fprintf( stderr, "(WW) readlink() /proc/self/exe failed: %s\n", strerror( errno ) );
+ path[0] = '.';
+ path[1] = '\0';
+ }
+ *(strrchr( path, '/' )) = '\0';
+ strncat( path, "/plugins", PATH_MAX );
+#ifdef __USE_GNU
+ }
+#endif
+ strncat( path, "/Glide64.ini", PATH_MAX );
// Open the file
ini = fopen (path, "r+b");
if (ini == NULL)
|