aboutsummaryrefslogtreecommitdiff
path: root/win32/mingw.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2026-02-27 13:57:40 +0000
committerRon Yorston <rmy@pobox.com>2026-02-27 14:27:40 +0000
commited525e2db10081f095d2fccc1b02830654470401 (patch)
tree4467394a255c596be9c3573d8d0b5e4f3eb3dcea /win32/mingw.c
parent05219c1f97be1dc7a3f825a5a658a137d90b03a2 (diff)
downloadbusybox-w32-long_paths.tar.gz
busybox-w32-long_paths.tar.bz2
busybox-w32-long_paths.zip
win32: add (some) long path supportlong_paths
Use the longPathAware manifest entry to handle path lengths above 260. This requires the LongPathsEnabled registry key to be set at run-time. Modify (some) WIN32 API calls to use the wide-character variant. These features are controlled by the build-time configuration option FEATURE_LONG_PATHS, which is not enabled by default.
Diffstat (limited to 'win32/mingw.c')
-rw-r--r--win32/mingw.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 122337d19..0c28d87fe 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -396,6 +396,9 @@ static inline mode_t file_attr_to_st_mode(DWORD attr)
396 396
397static int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata) 397static int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata)
398{ 398{
399#if ENABLE_FEATURE_LONG_PATHS
400 wchar_t wpath[32768];
401#endif
399 char *want_dir; 402 char *want_dir;
400 int dev = get_dev_type(fname); 403 int dev = get_dev_type(fname);
401 404
@@ -412,7 +415,18 @@ static int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata)
412 } 415 }
413 416
414 want_dir = last_char_is_dir_sep(fname); 417 want_dir = last_char_is_dir_sep(fname);
415 if (GetFileAttributesExA(fname, GetFileExInfoStandard, fdata)) { 418
419#if !ENABLE_FEATURE_LONG_PATHS
420 if (GetFileAttributesExA(fname, GetFileExInfoStandard, fdata))
421#else
422 /* Convert to wide string for long path support. CP_ACP is CP_UTF8
423 * when the UTF-8 manifest is active, else the system ANSI code page. */
424 if (MultiByteToWideChar(CP_ACP, 0, fname, -1, wpath, 32768) == 0)
425 return EINVAL;
426
427 if (GetFileAttributesExW(wpath, GetFileExInfoStandard, fdata))
428#endif
429 {
416 if (!(fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && want_dir) 430 if (!(fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && want_dir)
417 return ENOTDIR; 431 return ENOTDIR;
418 fdata->dwFileAttributes &= ~FILE_ATTRIBUTE_DEVICE; 432 fdata->dwFileAttributes &= ~FILE_ATTRIBUTE_DEVICE;
@@ -421,9 +435,16 @@ static int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata)
421 435
422 if (GetLastError() == ERROR_SHARING_VIOLATION) { 436 if (GetLastError() == ERROR_SHARING_VIOLATION) {
423 HANDLE hnd; 437 HANDLE hnd;
438#if !ENABLE_FEATURE_LONG_PATHS
424 WIN32_FIND_DATA fd; 439 WIN32_FIND_DATA fd;
425 440
426 if ((hnd=FindFirstFile(fname, &fd)) != INVALID_HANDLE_VALUE) { 441 if ((hnd=FindFirstFile(fname, &fd)) != INVALID_HANDLE_VALUE)
442#else
443 WIN32_FIND_DATAW fd;
444
445 if ((hnd=FindFirstFileW(wpath, &fd)) != INVALID_HANDLE_VALUE)
446#endif
447 {
427 fdata->dwFileAttributes = 448 fdata->dwFileAttributes =
428 fd.dwFileAttributes & ~FILE_ATTRIBUTE_DEVICE; 449 fd.dwFileAttributes & ~FILE_ATTRIBUTE_DEVICE;
429 fdata->ftCreationTime = fd.ftCreationTime; 450 fdata->ftCreationTime = fd.ftCreationTime;