diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 11:41:59 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 11:41:59 -0500 |
| commit | 7360583abdccbda0868437b843bb6fc2732e1a50 (patch) | |
| tree | c4599cec7c2f7f5e12a6c68520c91b086ead5169 /runtime/shims/file_system.cpp | |
| parent | 48ea5621ab6266bc9fea508a7ff839e29dd2c3b8 (diff) | |
| parent | 403d59060e89d706429ec9eca23b6ce7b7ef03c4 (diff) | |
Merge pull request #2122 from jaybeebabageyus
Diffstat (limited to 'runtime/shims/file_system.cpp')
| -rw-r--r-- | runtime/shims/file_system.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 12f0c75ae..2e7d93718 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp | |||
| @@ -478,6 +478,20 @@ HANDLE WINAPI create_file_a(LPCSTR name, DWORD access, DWORD share, LPSECURITY_A | |||
| 478 | return create_file_w(wide.c_str(), access, share, attributes, disposition, flags, template_file); | 478 | return create_file_w(wide.c_str(), access, share, attributes, disposition, flags, template_file); |
| 479 | } | 479 | } |
| 480 | 480 | ||
| 481 | HANDLE WINAPI create_file2(LPCWSTR name, DWORD access, DWORD share, DWORD disposition, | ||
| 482 | LPCREATEFILE2_EXTENDED_PARAMETERS params) { | ||
| 483 | if (!name) { | ||
| 484 | SetLastError(ERROR_INVALID_PARAMETER); | ||
| 485 | return INVALID_HANDLE_VALUE; | ||
| 486 | } | ||
| 487 | const Target t = open_target(name, access, disposition); | ||
| 488 | if (t.error) { | ||
| 489 | SetLastError(t.error); | ||
| 490 | return INVALID_HANDLE_VALUE; | ||
| 491 | } | ||
| 492 | return ::CreateFile2(t.path.c_str(), access, share, disposition, params); | ||
| 493 | } | ||
| 494 | |||
| 481 | DWORD WINAPI get_file_attributes_w(LPCWSTR name) { | 495 | DWORD WINAPI get_file_attributes_w(LPCWSTR name) { |
| 482 | if (!name) { | 496 | if (!name) { |
| 483 | SetLastError(ERROR_INVALID_PARAMETER); | 497 | SetLastError(ERROR_INVALID_PARAMETER); |
| @@ -548,6 +562,72 @@ HANDLE WINAPI find_first_file_w(LPCWSTR pattern, LPWIN32_FIND_DATAW data) { | |||
| 548 | return register_enumeration(std::move(e)); | 562 | return register_enumeration(std::move(e)); |
| 549 | } | 563 | } |
| 550 | 564 | ||
| 565 | HANDLE WINAPI find_first_file_ex_w(LPCWSTR pattern, FINDEX_INFO_LEVELS info_level, LPVOID data, | ||
| 566 | FINDEX_SEARCH_OPS search_op, LPVOID search_filter, DWORD additional_flags) { | ||
| 567 | if (!pattern || !data) { | ||
| 568 | SetLastError(ERROR_INVALID_PARAMETER); | ||
| 569 | return INVALID_HANDLE_VALUE; | ||
| 570 | } | ||
| 571 | std::vector<std::wstring> parts; | ||
| 572 | const Parsed parsed = parse_console(pattern, parts); | ||
| 573 | if (parsed == Parsed::Host) | ||
| 574 | return ::FindFirstFileExW(pattern, info_level, data, search_op, search_filter, additional_flags); | ||
| 575 | if (parsed == Parsed::Refused) { | ||
| 576 | SetLastError(ERROR_INVALID_NAME); | ||
| 577 | return INVALID_HANDLE_VALUE; | ||
| 578 | } | ||
| 579 | if (info_level != FindExInfoStandard && info_level != FindExInfoBasic) { | ||
| 580 | SetLastError(ERROR_INVALID_PARAMETER); | ||
| 581 | return INVALID_HANDLE_VALUE; | ||
| 582 | } | ||
| 583 | if (search_op != FindExSearchNameMatch && search_op != FindExSearchLimitToDirectories) { | ||
| 584 | SetLastError(ERROR_INVALID_PARAMETER); | ||
| 585 | return INVALID_HANDLE_VALUE; | ||
| 586 | } | ||
| 587 | |||
| 588 | std::vector<WIN32_FIND_DATAW> entries; | ||
| 589 | DWORD error = 0; | ||
| 590 | if (!collect(pattern, parts, entries, error)) { | ||
| 591 | SetLastError(error); | ||
| 592 | return INVALID_HANDLE_VALUE; | ||
| 593 | } | ||
| 594 | if (search_op == FindExSearchLimitToDirectories) { | ||
| 595 | std::vector<WIN32_FIND_DATAW> dirs_only; | ||
| 596 | for (auto& entry : entries) | ||
| 597 | if ((entry.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) dirs_only.push_back(entry); | ||
| 598 | entries = std::move(dirs_only); | ||
| 599 | if (entries.empty()) { | ||
| 600 | SetLastError(ERROR_FILE_NOT_FOUND); | ||
| 601 | return INVALID_HANDLE_VALUE; | ||
| 602 | } | ||
| 603 | } | ||
| 604 | if (info_level == FindExInfoBasic) { | ||
| 605 | for (auto& entry : entries) entry.cAlternateFileName[0] = L'\0'; | ||
| 606 | } | ||
| 607 | auto e = std::make_unique<Enumeration>(); | ||
| 608 | e->entries = std::move(entries); | ||
| 609 | e->next = 1; | ||
| 610 | *static_cast<LPWIN32_FIND_DATAW>(data) = e->entries[0]; | ||
| 611 | return register_enumeration(std::move(e)); | ||
| 612 | } | ||
| 613 | |||
| 614 | HANDLE WINAPI find_first_file_ex_a(LPCSTR pattern, FINDEX_INFO_LEVELS info_level, LPVOID data, | ||
| 615 | FINDEX_SEARCH_OPS search_op, LPVOID search_filter, DWORD additional_flags) { | ||
| 616 | if (!pattern || !data) { | ||
| 617 | SetLastError(ERROR_INVALID_PARAMETER); | ||
| 618 | return INVALID_HANDLE_VALUE; | ||
| 619 | } | ||
| 620 | const std::wstring wide = widen_ansi(pattern); | ||
| 621 | std::vector<std::wstring> parts; | ||
| 622 | const Parsed parsed = parse_console(wide, parts); | ||
| 623 | if (parsed == Parsed::Host) | ||
| 624 | return ::FindFirstFileExA(pattern, info_level, data, search_op, search_filter, additional_flags); | ||
| 625 | WIN32_FIND_DATAW wide_data{}; | ||
| 626 | const HANDLE h = find_first_file_ex_w(wide.c_str(), info_level, &wide_data, search_op, search_filter, additional_flags); | ||
| 627 | if (h != INVALID_HANDLE_VALUE) to_ansi(wide_data, static_cast<LPWIN32_FIND_DATAA>(data)); | ||
| 628 | return h; | ||
| 629 | } | ||
| 630 | |||
| 551 | HANDLE WINAPI find_first_file_a(LPCSTR pattern, LPWIN32_FIND_DATAA data) { | 631 | HANDLE WINAPI find_first_file_a(LPCSTR pattern, LPWIN32_FIND_DATAA data) { |
| 552 | if (!pattern || !data) { | 632 | if (!pattern || !data) { |
| 553 | SetLastError(ERROR_INVALID_PARAMETER); | 633 | SetLastError(ERROR_INVALID_PARAMETER); |
| @@ -949,8 +1029,11 @@ using namespace rt::fs; | |||
| 949 | #define FILE_API(dll) \ | 1029 | #define FILE_API(dll) \ |
| 950 | {dll, "CreateFileA", reinterpret_cast<void*>(&create_file_a)}, \ | 1030 | {dll, "CreateFileA", reinterpret_cast<void*>(&create_file_a)}, \ |
| 951 | {dll, "CreateFileW", reinterpret_cast<void*>(&create_file_w)}, \ | 1031 | {dll, "CreateFileW", reinterpret_cast<void*>(&create_file_w)}, \ |
| 1032 | {dll, "CreateFile2", reinterpret_cast<void*>(&create_file2)}, \ | ||
| 952 | {dll, "FindFirstFileA", reinterpret_cast<void*>(&find_first_file_a)}, \ | 1033 | {dll, "FindFirstFileA", reinterpret_cast<void*>(&find_first_file_a)}, \ |
| 953 | {dll, "FindFirstFileW", reinterpret_cast<void*>(&find_first_file_w)}, \ | 1034 | {dll, "FindFirstFileW", reinterpret_cast<void*>(&find_first_file_w)}, \ |
| 1035 | {dll, "FindFirstFileExA", reinterpret_cast<void*>(&find_first_file_ex_a)}, \ | ||
| 1036 | {dll, "FindFirstFileExW", reinterpret_cast<void*>(&find_first_file_ex_w)}, \ | ||
| 954 | {dll, "FindNextFileA", reinterpret_cast<void*>(&find_next_file_a)}, \ | 1037 | {dll, "FindNextFileA", reinterpret_cast<void*>(&find_next_file_a)}, \ |
| 955 | {dll, "FindNextFileW", reinterpret_cast<void*>(&find_next_file_w)}, \ | 1038 | {dll, "FindNextFileW", reinterpret_cast<void*>(&find_next_file_w)}, \ |
| 956 | {dll, "FindClose", reinterpret_cast<void*>(&find_close)}, \ | 1039 | {dll, "FindClose", reinterpret_cast<void*>(&find_close)}, \ |