From ef5287d2a91383be8f1ba1a840fc232bfe804c9c Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Thu, 7 Nov 2024 13:41:47 -0800 Subject: [PATCH] switch to os_full_path_from_path --- src/linker/lnk.c | 12 ++++++------ src/linker/lnk_config.c | 8 ++++---- src/linker/os_ext/core/os_core_win32.c | 21 --------------------- src/os/core/win32/os_core_win32.c | 17 ++++++++++++----- 4 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/linker/lnk.c b/src/linker/lnk.c index 2d5127b8..2aefabf8 100644 --- a/src/linker/lnk.c +++ b/src/linker/lnk.c @@ -1285,11 +1285,11 @@ lnk_push_input_from_lazy(Arena *arena, PathStyle path_style, LNK_LazySymbol *laz } LNK_InputObj *input = lnk_input_obj_list_push(arena, input_obj_list); - input->is_thin = is_thin; - input->dedup_id = push_str8f(arena, "%S(%S)", lazy->lib->path, obj_path); - input->path = obj_path; - input->data = member_info.data; - input->lib_path = lazy->lib->path; + input->is_thin = is_thin; + input->dedup_id = push_str8f(arena, "%S/%S", lazy->lib->path, obj_path); + input->path = obj_path; + input->data = member_info.data; + input->lib_path = lazy->lib->path; } break; } } @@ -3557,7 +3557,7 @@ l.count += 1; \ continue; } - String8 full_path = os_make_full_path(scratch.arena, input->dedup_id); + String8 full_path = os_full_path_from_path(scratch.arena, input->dedup_id); B32 was_full_path_used = hash_table_search_path_u64(loaded_obj_ht, full_path, 0); if (was_full_path_used) { continue; diff --git a/src/linker/lnk_config.c b/src/linker/lnk_config.c index b5d03bf5..f501f6a8 100644 --- a/src/linker/lnk_config.c +++ b/src/linker/lnk_config.c @@ -1819,25 +1819,25 @@ lnk_config_from_cmd_line(Arena *arena, String8List raw_cmd_line) String8 ext = (config->file_characteristics & PE_ImageFileCharacteristic_FILE_DLL) ? str8_lit("dll") : str8_lit("exe"); config->image_name = make_file_path_with_ext(scratch.arena, name, ext); } - config->image_name = os_make_full_path(arena, config->image_name); + config->image_name = os_full_path_from_path(arena, config->image_name); // handle empty /PDB if (!lnk_cmd_line_has_switch(cmd_line, LNK_CmdSwitch_Pdb)) { config->pdb_name = make_file_path_with_ext(arena, config->image_name, str8_lit("pdb")); } - config->pdb_name = os_make_full_path(arena, config->pdb_name); + config->pdb_name = os_full_path_from_path(arena, config->pdb_name); // handle empty /RAD_DEBUG_NAME if (!lnk_cmd_line_has_switch(cmd_line, LNK_CmdSwitch_Rad_DebugName)) { config->rad_debug_name = make_file_name_with_ext(arena, config->image_name, str8_lit("rdi")); } - config->rad_debug_name = os_make_full_path(arena, config->rad_debug_name); + config->rad_debug_name = os_full_path_from_path(arena, config->rad_debug_name); // handle empty /IMPLIB if (!lnk_cmd_line_has_switch(cmd_line, LNK_CmdSwitch_ImpLib)) { config->imp_lib_name = make_file_name_with_ext(arena, config->image_name, str8_lit("lib")); } - config->imp_lib_name = os_make_full_path(arena, config->imp_lib_name); + config->imp_lib_name = os_full_path_from_path(arena, config->imp_lib_name); // handle empty /MANIFESTFILE if (!lnk_cmd_line_has_switch(cmd_line, LNK_CmdSwitch_ManifestFile)) { diff --git a/src/linker/os_ext/core/os_core_win32.c b/src/linker/os_ext/core/os_core_win32.c index f078a73d..a50afce4 100644 --- a/src/linker/os_ext/core/os_core_win32.c +++ b/src/linker/os_ext/core/os_core_win32.c @@ -73,27 +73,6 @@ os_w32_is_path_relative_current_directory(String8 path) return 1; } -internal String8 -os_make_full_path(Arena *arena, String8 path) -{ - String8 full_path; - if (os_w32_is_path_relative_current_directory(path)) { - Temp scratch = scratch_begin(&arena, 1); - String8 current_dir = os_get_current_path(scratch.arena); - String8List list = {0}; - str8_list_push(scratch.arena, &list, current_dir); - str8_list_push(scratch.arena, &list, path); - String8 temp_full_path = str8_list_join(scratch.arena, &list, &(StringJoin){ .sep = str8_lit_comp("\\") }); - String8List split_full_path = str8_split_path(scratch.arena, temp_full_path); - str8_path_list_resolve_dots_in_place(&split_full_path, PathStyle_WindowsAbsolute); - full_path = str8_list_join(arena, &split_full_path, &(StringJoin){ .sep = str8_lit_comp("\\") }); - scratch_end(scratch); - } else { - full_path = push_str8_copy(arena, path); - } - return full_path; -} - internal B32 os_folder_path_exists(String8 path) { diff --git a/src/os/core/win32/os_core_win32.c b/src/os/core/win32/os_core_win32.c index 68cc194f..d45be2c5 100644 --- a/src/os/core/win32/os_core_win32.c +++ b/src/os/core/win32/os_core_win32.c @@ -494,11 +494,18 @@ internal String8 os_full_path_from_path(Arena *arena, String8 path) { Temp scratch = scratch_begin(&arena, 1); - DWORD buffer_size = MAX_PATH + 1; - U16 *buffer = push_array_no_zero(scratch.arena, U16, buffer_size); - String16 path16 = str16_from_8(scratch.arena, path); - DWORD path16_size = GetFullPathNameW((WCHAR*)path16.str, buffer_size, (WCHAR*)buffer, NULL); - String8 full_path = str8_from_16(arena, str16(buffer, path16_size)); + DWORD buffer_size = Max(MAX_PATH, path.size * 2) + 1; + String16 path16 = str16_from_8(scratch.arena, path); + WCHAR *buffer = push_array_no_zero(scratch.arena, WCHAR, buffer_size); + DWORD path16_size = GetFullPathNameW((WCHAR*)path16.str, buffer_size, buffer, NULL); + if(path16_size > buffer_size) + { + arena_pop(scratch.arena, buffer_size); + buffer_size = path16_size + 1; + buffer = push_array_no_zero(scratch.arena, WCHAR, buffer_size); + path16_size = GetFullPathNameW((WCHAR*)path16.str, buffer_size, buffer, NULL); + } + String8 full_path = str8_from_16(arena, str16((U16*)buffer, path16_size)); scratch_end(scratch); return full_path; }