diff options
Diffstat (limited to 'win32/mingw.c')
-rw-r--r-- | win32/mingw.c | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index 7e42e4434..6544d11ad 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -1146,17 +1146,6 @@ static char *gethomedir(void) | |||
1146 | return buf; | 1146 | return buf; |
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | static char *getsysdir(void) | ||
1150 | { | ||
1151 | static char *buf = NULL; | ||
1152 | |||
1153 | if (!buf) { | ||
1154 | buf = xzalloc(PATH_MAX); | ||
1155 | GetSystemDirectory(buf, PATH_MAX); | ||
1156 | } | ||
1157 | return buf; | ||
1158 | } | ||
1159 | |||
1160 | #define NAME_LEN 100 | 1149 | #define NAME_LEN 100 |
1161 | char *get_user_name(void) | 1150 | char *get_user_name(void) |
1162 | { | 1151 | { |
@@ -2297,27 +2286,21 @@ int root_len(const char *path) | |||
2297 | 2286 | ||
2298 | const char *get_system_drive(void) | 2287 | const char *get_system_drive(void) |
2299 | { | 2288 | { |
2300 | static char *drive = NULL; | 2289 | static const char *drive = NULL; |
2290 | char sysdir[PATH_MAX]; | ||
2301 | int len; | 2291 | int len; |
2302 | 2292 | ||
2303 | if (drive == NULL) { | 2293 | if (drive == NULL) { |
2304 | const char *sysdir = getsysdir(); | 2294 | UINT ret = GetSystemDirectory(sysdir, PATH_MAX); |
2305 | if ((len=root_len(sysdir))) { | 2295 | if ((ret != 0 && ret < PATH_MAX) && (len=root_len(sysdir))) |
2306 | drive = xstrndup(sysdir, len); | 2296 | drive = xstrndup(sysdir, len); |
2307 | } | 2297 | else |
2298 | drive = ""; | ||
2308 | } | 2299 | } |
2309 | 2300 | ||
2310 | return getenv(BB_SYSTEMROOT) ?: drive; | 2301 | return getenv(BB_SYSTEMROOT) ?: drive; |
2311 | } | 2302 | } |
2312 | 2303 | ||
2313 | /* Return pointer to system drive if path is of form '/file', else NULL */ | ||
2314 | const char *need_system_drive(const char *path) | ||
2315 | { | ||
2316 | if (root_len(path) == 0 && (path[0] == '/' || path[0] == '\\')) | ||
2317 | return get_system_drive(); | ||
2318 | return NULL; | ||
2319 | } | ||
2320 | |||
2321 | int chdir_system_drive(void) | 2304 | int chdir_system_drive(void) |
2322 | { | 2305 | { |
2323 | const char *sd = get_system_drive(); | 2306 | const char *sd = get_system_drive(); |
@@ -2409,10 +2392,14 @@ void *get_proc_addr(const char *dll, const char *function, | |||
2409 | * on Windows 7. If it does, retry using LoadLibrary with an | 2392 | * on Windows 7. If it does, retry using LoadLibrary with an |
2410 | * explicit, backslash-separated path. */ | 2393 | * explicit, backslash-separated path. */ |
2411 | if (!hnd) { | 2394 | if (!hnd) { |
2412 | char *path = concat_path_file(getsysdir(), dll); | 2395 | char buf[PATH_MAX]; |
2413 | slash_to_bs(path); | 2396 | UINT ret = GetSystemDirectory(buf, PATH_MAX); |
2414 | hnd = LoadLibrary(path); | 2397 | if (ret != 0 && ret < PATH_MAX) { |
2415 | free(path); | 2398 | char *path = concat_path_file(buf, dll); |
2399 | slash_to_bs(path); | ||
2400 | hnd = LoadLibrary(path); | ||
2401 | free(path); | ||
2402 | } | ||
2416 | } | 2403 | } |
2417 | 2404 | ||
2418 | if (hnd) | 2405 | if (hnd) |