summaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/pathutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/pathutil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/pathutil.cpp33
1 files changed, 2 insertions, 31 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp
index dc33e656..becfc67e 100644
--- a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp
@@ -181,10 +181,8 @@ DAPI_(HRESULT) PathExpand(
181 Assert(wzRelativePath); 181 Assert(wzRelativePath);
182 182
183 HRESULT hr = S_OK; 183 HRESULT hr = S_OK;
184 DWORD cch = 0;
185 LPWSTR sczExpandedPath = NULL; 184 LPWSTR sczExpandedPath = NULL;
186 SIZE_T cchWritten = 0; 185 SIZE_T cchWritten = 0;
187 DWORD cchExpandedPath = 0;
188 LPWSTR sczFullPath = NULL; 186 LPWSTR sczFullPath = NULL;
189 DWORD dwPrefixFlags = 0; 187 DWORD dwPrefixFlags = 0;
190 188
@@ -193,35 +191,8 @@ DAPI_(HRESULT) PathExpand(
193 // 191 //
194 if (dwResolveFlags & PATH_EXPAND_ENVIRONMENT) 192 if (dwResolveFlags & PATH_EXPAND_ENVIRONMENT)
195 { 193 {
196 cchExpandedPath = PATH_GOOD_ENOUGH; 194 hr = EnvExpandEnvironmentStrings(wzRelativePath, &sczExpandedPath, &cchWritten);
197 195 PathExitOnFailure(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
198 hr = StrAlloc(&sczExpandedPath, cchExpandedPath);
199 PathExitOnFailure(hr, "Failed to allocate space for expanded path.");
200
201 cch = ::ExpandEnvironmentStringsW(wzRelativePath, sczExpandedPath, cchExpandedPath);
202 if (0 == cch)
203 {
204 PathExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
205 }
206 else if (cchExpandedPath < cch)
207 {
208 cchExpandedPath = cch;
209 hr = StrAlloc(&sczExpandedPath, cchExpandedPath);
210 PathExitOnFailure(hr, "Failed to re-allocate more space for expanded path.");
211
212 cch = ::ExpandEnvironmentStringsW(wzRelativePath, sczExpandedPath, cchExpandedPath);
213 if (0 == cch)
214 {
215 PathExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
216 }
217 else if (cchExpandedPath < cch)
218 {
219 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
220 PathExitOnRootFailure(hr, "Failed to allocate buffer for expanded path.");
221 }
222 }
223
224 cchWritten = cch;
225 } 196 }
226 197
227 // 198 //