Revision 6170540b vl.c
b/vl.c | ||
---|---|---|
1986 | 1986 |
return -1; |
1987 | 1987 |
} |
1988 | 1988 |
|
1989 |
#ifdef _WIN32 |
|
1990 |
/* Look for support files in the same directory as the executable. */ |
|
1991 |
static char *find_datadir(const char *argv0) |
|
1992 |
{ |
|
1993 |
char *p; |
|
1994 |
char buf[MAX_PATH]; |
|
1995 |
DWORD len; |
|
1996 |
|
|
1997 |
len = GetModuleFileName(NULL, buf, sizeof(buf) - 1); |
|
1998 |
if (len == 0) { |
|
1999 |
return NULL; |
|
2000 |
} |
|
2001 |
|
|
2002 |
buf[len] = 0; |
|
2003 |
p = buf + len - 1; |
|
2004 |
while (p != buf && *p != '\\') |
|
2005 |
p--; |
|
2006 |
*p = 0; |
|
2007 |
if (access(buf, R_OK) == 0) { |
|
2008 |
return qemu_strdup(buf); |
|
2009 |
} |
|
2010 |
return NULL; |
|
2011 |
} |
|
2012 |
#else /* !_WIN32 */ |
|
2013 |
|
|
2014 |
/* Find a likely location for support files using the location of the binary. |
|
2015 |
For installed binaries this will be "$bindir/../share/qemu". When |
|
2016 |
running from the build tree this will be "$bindir/../pc-bios". */ |
|
2017 |
#define SHARE_SUFFIX "/share/qemu" |
|
2018 |
#define BUILD_SUFFIX "/pc-bios" |
|
2019 |
static char *find_datadir(const char *argv0) |
|
2020 |
{ |
|
2021 |
char *dir; |
|
2022 |
char *p = NULL; |
|
2023 |
char *res; |
|
2024 |
char buf[PATH_MAX]; |
|
2025 |
size_t max_len; |
|
2026 |
|
|
2027 |
#if defined(__linux__) |
|
2028 |
{ |
|
2029 |
int len; |
|
2030 |
len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); |
|
2031 |
if (len > 0) { |
|
2032 |
buf[len] = 0; |
|
2033 |
p = buf; |
|
2034 |
} |
|
2035 |
} |
|
2036 |
#elif defined(__FreeBSD__) |
|
2037 |
{ |
|
2038 |
static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; |
|
2039 |
size_t len = sizeof(buf) - 1; |
|
2040 |
|
|
2041 |
*buf = '\0'; |
|
2042 |
if (!sysctl(mib, sizeof(mib)/sizeof(*mib), buf, &len, NULL, 0) && |
|
2043 |
*buf) { |
|
2044 |
buf[sizeof(buf) - 1] = '\0'; |
|
2045 |
p = buf; |
|
2046 |
} |
|
2047 |
} |
|
2048 |
#endif |
|
2049 |
/* If we don't have any way of figuring out the actual executable |
|
2050 |
location then try argv[0]. */ |
|
2051 |
if (!p) { |
|
2052 |
p = realpath(argv0, buf); |
|
2053 |
if (!p) { |
|
2054 |
return NULL; |
|
2055 |
} |
|
2056 |
} |
|
2057 |
dir = dirname(p); |
|
2058 |
dir = dirname(dir); |
|
2059 |
|
|
2060 |
max_len = strlen(dir) + |
|
2061 |
MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1; |
|
2062 |
res = qemu_mallocz(max_len); |
|
2063 |
snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX); |
|
2064 |
if (access(res, R_OK)) { |
|
2065 |
snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX); |
|
2066 |
if (access(res, R_OK)) { |
|
2067 |
qemu_free(res); |
|
2068 |
res = NULL; |
|
2069 |
} |
|
2070 |
} |
|
2071 |
|
|
2072 |
return res; |
|
2073 |
} |
|
2074 |
#undef SHARE_SUFFIX |
|
2075 |
#undef BUILD_SUFFIX |
|
2076 |
#endif |
|
2077 |
|
|
2078 | 1989 |
char *qemu_find_file(int type, const char *name) |
2079 | 1990 |
{ |
2080 | 1991 |
int len; |
... | ... | |
3223 | 3134 |
/* If no data_dir is specified then try to find it relative to the |
3224 | 3135 |
executable path. */ |
3225 | 3136 |
if (!data_dir) { |
3226 |
data_dir = find_datadir(argv[0]); |
|
3137 |
data_dir = os_find_datadir(argv[0]);
|
|
3227 | 3138 |
} |
3228 | 3139 |
/* If all else fails use the install patch specified when building. */ |
3229 | 3140 |
if (!data_dir) { |
Also available in: Unified diff