Author: akhaldi
Date: Thu Apr 25 22:52:34 2013
New Revision: 58854
URL:
http://svn.reactos.org/svn/reactos?rev=58854&view=rev
Log:
[SHELL32]
* Sync DoEnvironmentSubst{A,W} with Wine 1.5.26. Fixes issues spotted by Victor Martinez.
CORE-7124 #resolve
Modified:
trunk/reactos/dll/win32/shell32/shellord.cpp
Modified: trunk/reactos/dll/win32/shell32/shellord.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shellord…
==============================================================================
--- trunk/reactos/dll/win32/shell32/shellord.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/shellord.cpp [iso-8859-1] Thu Apr 25 22:52:34 2013
@@ -1492,11 +1492,41 @@
}
/************************************************************************
- * DoEnvironmentSubstA [SHELL32.@]
- *
- * Replace %KEYWORD% in the str with the value of variable KEYWORD
- * from environment. If it is not found the %KEYWORD% is left
- * intact. If the buffer is too small, str is not modified.
+ * DoEnvironmentSubstA [SHELL32.@]
+ *
+ * See DoEnvironmentSubstW.
+ */
+EXTERN_C DWORD WINAPI DoEnvironmentSubstA(LPSTR pszString, UINT cchString)
+{
+ LPSTR dst;
+ BOOL res = FALSE;
+ DWORD len = cchString;
+
+ TRACE("(%s, %d)\n", debugstr_a(pszString), cchString);
+ if (pszString == NULL) /* Really return 0? */
+ return 0;
+ if ((dst = (LPSTR)HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(CHAR))))
+ {
+ len = ExpandEnvironmentStringsA(pszString, dst, cchString);
+ /* len includes the terminating 0 */
+ if (len && len < cchString)
+ {
+ res = TRUE;
+ memcpy(pszString, dst, len);
+ }
+ else
+ len = cchString;
+
+ HeapFree(GetProcessHeap(), 0, dst);
+ }
+ return MAKELONG(len, res);
+}
+
+/************************************************************************
+ * DoEnvironmentSubstW [SHELL32.@]
+ *
+ * Replace all %KEYWORD% in the string with the value of the named
+ * environment variable. If the buffer is too small, the string is not modified.
*
* PARAMS
* pszString [I] '\0' terminated string with %keyword%.
@@ -1504,51 +1534,36 @@
* cchString [I] size of str.
*
* RETURNS
- * cchString length in the HIWORD;
- * TRUE in LOWORD if subst was successful and FALSE in other case
- */
-EXTERN_C DWORD WINAPI DoEnvironmentSubstA(LPSTR pszString, UINT cchString)
-{
- LPSTR dst;
+ * Success: The string in the buffer is updated
+ * HIWORD: TRUE
+ * LOWORD: characters used in the buffer, including space for the terminating
0
+ * Failure: buffer too small. The string is not modified.
+ * HIWORD: FALSE
+ * LOWORD: provided size of the buffer in characters
+ */
+EXTERN_C DWORD WINAPI DoEnvironmentSubstW(LPWSTR pszString, UINT cchString)
+{
+ LPWSTR dst;
BOOL res = FALSE;
- FIXME("(%s, %d) stub\n", debugstr_a(pszString), cchString);
- if (pszString == NULL) /* Really return 0? */
- return 0;
- if ((dst = (LPSTR)HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(CHAR))))
- {
- DWORD num = ExpandEnvironmentStringsA(pszString, dst, cchString);
- if (num && num < cchString) /* dest buffer is too small */
+ DWORD len = cchString;
+
+ TRACE("(%s, %d)\n", debugstr_w(pszString), cchString);
+
+ if ((cchString < MAXLONG) && (dst = (LPWSTR)HeapAlloc(GetProcessHeap(), 0,
cchString * sizeof(WCHAR))))
+ {
+ len = ExpandEnvironmentStringsW(pszString, dst, cchString);
+ /* len includes the terminating 0 */
+ if (len && len <= cchString)
{
res = TRUE;
- memcpy(pszString, dst, num);
+ memcpy(pszString, dst, len * sizeof(WCHAR));
}
+ else
+ len = cchString;
+
HeapFree(GetProcessHeap(), 0, dst);
}
- return MAKELONG(res,cchString); /* Always cchString? */
-}
-
-/************************************************************************
- * DoEnvironmentSubstW [SHELL32.@]
- *
- * See DoEnvironmentSubstA.
- */
-EXTERN_C DWORD WINAPI DoEnvironmentSubstW(LPWSTR pszString, UINT cchString)
-{
- LPWSTR dst;
- BOOL res = FALSE;
- FIXME("(%s, %d): stub\n", debugstr_w(pszString), cchString);
- if ((dst = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(WCHAR))))
- {
- DWORD num = ExpandEnvironmentStringsW(pszString, dst, cchString);
- if (num)
- {
- res = TRUE;
- wcscpy(pszString, dst);
- }
- HeapFree(GetProcessHeap(), 0, dst);
- }
-
- return MAKELONG(res,cchString);
+ return MAKELONG(len, res);
}
/************************************************************************