/* * Helper function for search_path */ static WCHAR* path_search_walk_ext(const WCHAR* dir, size_t dir_len, const WCHAR* name, size_t name_len, WCHAR* cwd, size_t cwd_len, int name_has_ext) { WCHAR* result; /* If the name itself has a nonempty extension, try this extension first */ if (name_has_ext) { result = search_path_join_test(dir, dir_len, name, name_len, L"", 0, cwd, cwd_len); if (result != NULL) { return result; } } /* Try .com extension */ result = search_path_join_test(dir, dir_len, name, name_len, L"com", 3, cwd, cwd_len); if (result != NULL) { return result; } /* Try .exe extension */ result = search_path_join_test(dir, dir_len, name, name_len, L"exe", 3, cwd, cwd_len); if (result != NULL) { return result; } return NULL; }
/* * Helper function for search_path */ static wchar_t* path_search_walk_ext(const wchar_t *dir, int dir_len, const wchar_t *name, int name_len, wchar_t *cwd, int cwd_len, const wchar_t *path_ext, int name_has_ext) { wchar_t* result = NULL; const wchar_t *ext_start, *ext_end = path_ext; /* If the name itself has a nonemtpy extension, try this extension first */ if (name_has_ext) { result = search_path_join_test(dir, dir_len, name, name_len, L"", 0, cwd, cwd_len); } /* Add path_ext extensions and try to find a name that matches */ while (result == NULL) { if (*ext_end == L'\0') { break; } /* Skip the separator that ext_end now points to */ if (ext_end != path_ext) { ext_end++; } /* Find the next dot in path_ext */ ext_start = wcschr(ext_end, L'.'); if (ext_start == NULL) { break; } /* Skip the dot */ ext_start++; /* Slice until we found a ; or alternatively a \0 */ ext_end = wcschr(ext_start, L';'); if (ext_end == NULL) { ext_end = wcschr(ext_start, '\0'); } result = search_path_join_test(dir, dir_len, name, name_len, ext_start, (ext_end - ext_start), cwd, cwd_len); } return result; }