Revision 10f5bff6 os-posix.c
b/os-posix.c | ||
---|---|---|
84 | 84 |
running from the build tree this will be "$bindir/../pc-bios". */ |
85 | 85 |
#define SHARE_SUFFIX "/share/qemu" |
86 | 86 |
#define BUILD_SUFFIX "/pc-bios" |
87 |
char *os_find_datadir(const char *argv0)
|
|
87 |
char *os_find_datadir(void)
|
|
88 | 88 |
{ |
89 |
char *dir; |
|
90 |
char *p = NULL; |
|
89 |
char *dir, *exec_dir; |
|
91 | 90 |
char *res; |
92 |
char buf[PATH_MAX]; |
|
93 | 91 |
size_t max_len; |
94 | 92 |
|
95 |
#if defined(__linux__) |
|
96 |
{ |
|
97 |
int len; |
|
98 |
len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); |
|
99 |
if (len > 0) { |
|
100 |
buf[len] = 0; |
|
101 |
p = buf; |
|
102 |
} |
|
103 |
} |
|
104 |
#elif defined(__FreeBSD__) |
|
105 |
{ |
|
106 |
static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; |
|
107 |
size_t len = sizeof(buf) - 1; |
|
108 |
|
|
109 |
*buf = '\0'; |
|
110 |
if (!sysctl(mib, ARRAY_SIZE(mib), buf, &len, NULL, 0) && |
|
111 |
*buf) { |
|
112 |
buf[sizeof(buf) - 1] = '\0'; |
|
113 |
p = buf; |
|
114 |
} |
|
115 |
} |
|
116 |
#endif |
|
117 |
/* If we don't have any way of figuring out the actual executable |
|
118 |
location then try argv[0]. */ |
|
119 |
if (!p) { |
|
120 |
p = realpath(argv0, buf); |
|
121 |
if (!p) { |
|
122 |
return NULL; |
|
123 |
} |
|
93 |
exec_dir = qemu_get_exec_dir(); |
|
94 |
if (exec_dir == NULL) { |
|
95 |
return NULL; |
|
124 | 96 |
} |
125 |
dir = dirname(p); |
|
126 |
dir = dirname(dir); |
|
97 |
dir = dirname(exec_dir); |
|
127 | 98 |
|
128 | 99 |
max_len = strlen(dir) + |
129 | 100 |
MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1; |
... | ... | |
137 | 108 |
} |
138 | 109 |
} |
139 | 110 |
|
111 |
g_free(exec_dir); |
|
140 | 112 |
return res; |
141 | 113 |
} |
142 | 114 |
#undef SHARE_SUFFIX |
Also available in: Unified diff