Index: Program.inc =================================================================== --- Program.inc +++ Program.inc @@ -75,9 +75,26 @@ do { U16Result.reserve(Len); - Len = ::SearchPathW(Path, c_str(U16Name), - U16Ext.empty() ? nullptr : c_str(U16Ext), - U16Result.capacity(), U16Result.data(), nullptr); + auto I = std::find_end(U16Name.begin(), U16Name.end(), U16Ext.begin(), + U16Ext.end()); + // if has this extension at the end + if (I != U16Name.end() && (I + U16Ext.size()) == U16Name.end()) { + Len = ::SearchPathW(Path, c_str(U16Name), nullptr, U16Result.capacity(), + U16Result.data(), nullptr); + } else { + // if no - lets attach the extension. That branch is needed for files + // with a point in name like aaa.bbb. SearchPathW will not add extension + // from its argument to such files and that is a problem sometimes. So + // we need to add extension manually. + SmallVector U16NameExt; + if (std::error_code EC = + windows::UTF8ToUTF16(Twine(Name + Ext).str(), U16NameExt)) + return EC; + + Len = ::SearchPathW(Path, c_str(U16NameExt), nullptr, + U16Result.capacity(), U16Result.data(), nullptr); + } + } while (Len > U16Result.capacity()); if (Len != 0)