|
31 | 31 | static inline int *get_perrno(void) { return &errno; }
|
32 | 32 |
|
33 | 33 | #include "busybox.h"
|
| 34 | +#include "path-convert.h" |
34 | 35 |
|
35 | 36 | #if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
|
36 | 37 | || defined(__APPLE__) \
|
@@ -1225,6 +1226,22 @@ get_script_content(unsigned n UNUSED_PARAM)
|
1225 | 1226 |
|
1226 | 1227 | #endif /* defined(SINGLE_APPLET_MAIN) */
|
1227 | 1228 |
|
| 1229 | +#if ENABLE_PLATFORM_MINGW32 |
| 1230 | +static char *xwcstoutf(wchar_t *wcs) |
| 1231 | +{ |
| 1232 | + DWORD size = WideCharToMultiByte(CP_UTF8, 0, wcs, -1, NULL, 0, NULL, NULL) + 1; |
| 1233 | + char *buf; |
| 1234 | + |
| 1235 | + if (!size) |
| 1236 | + bb_error_msg_and_die("could not convert '%ls' to UTF-8", wcs); |
| 1237 | + buf = xmalloc(size); |
| 1238 | + if (WideCharToMultiByte(CP_UTF8, 0, wcs, -1, buf, size, NULL, NULL)) |
| 1239 | + return buf; |
| 1240 | + free(buf); |
| 1241 | + bb_error_msg_and_die("could not convert '%ls' to UTF-8", wcs); |
| 1242 | +} |
| 1243 | +#endif |
| 1244 | + |
1228 | 1245 | #if ENABLE_BUILD_LIBBUSYBOX
|
1229 | 1246 | int lbb_main(char **argv)
|
1230 | 1247 | #else
|
@@ -1333,19 +1350,29 @@ int main(int argc UNUSED_PARAM, char **argv)
|
1333 | 1350 | /* Manually convert non-ASCII environment entries from UTF-16 */
|
1334 | 1351 | for (i = 0; wenv[i]; i++) {
|
1335 | 1352 | for (p = wenv + i; *p; p++)
|
1336 |
| - if (*p & ~0x7f) { |
| 1353 | + if (!_wcsnicmp(wenv + i, L"PATH=", 5)) { |
| 1354 | + char *orig = xwcstoutf(wenv + i + 5); |
| 1355 | + char *converted = path_convert_path_list(orig, PATH_CONVERT_MIXED); |
| 1356 | + size_t len; |
| 1357 | + |
| 1358 | + if (!converted) |
| 1359 | + bb_error_msg_and_die("could not convert path list '%s'", orig); |
| 1360 | + |
| 1361 | + len = strlen(converted); |
| 1362 | + converted = xrealloc(converted, len + 6); |
| 1363 | + memmove(converted + 5, converted, len + 1); |
| 1364 | + memcpy(converted, "PATH=", 5); |
| 1365 | + |
| 1366 | + putenv(converted); |
| 1367 | + |
| 1368 | + free(converted); |
| 1369 | + free(orig); |
| 1370 | + break; |
| 1371 | + } else if (*p & ~0x7f) { |
1337 | 1372 | /* Non-ASCII name or value */
|
1338 |
| - DWORD size = WideCharToMultiByte(CP_UTF8, 0, |
1339 |
| - wenv + i, -1, NULL, 0, NULL, NULL) + 1; |
1340 |
| - char *buf; |
1341 |
| - |
1342 |
| - if (!size) |
1343 |
| - break; |
1344 |
| - buf = malloc(size); |
1345 |
| - if (!buf) |
1346 |
| - bb_error_msg_and_die("Out of memory"); |
1347 |
| - if (WideCharToMultiByte(CP_UTF8, 0, |
1348 |
| - wenv + i, -1, buf, size, NULL, NULL)) |
| 1373 | + char *buf = xwcstoutf(wenv + i); |
| 1374 | + |
| 1375 | + if (buf) |
1349 | 1376 | /* if we could not convert, punt */
|
1350 | 1377 | putenv(buf);
|
1351 | 1378 | free(buf);
|
|
0 commit comments