Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.0 KiB

  1. /****************************************************************************/
  2. /* */
  3. /* enpenv.c - */
  4. /* */
  5. /* Routines for expanding environment strings */
  6. /* */
  7. /****************************************************************************/
  8. #include "shellprv.h"
  9. //-------------------------------------------------------------------------
  10. // The given string is parsed and all environment variables
  11. // are expanded. If the expansion doesn't over fill the buffer
  12. // then the length of the new string will be returned in the
  13. // hiword and TRUE in the low word. If the expansion would over
  14. // fill the buffer then the original string is left unexpanded,
  15. // the original length in the high word and FALSE in the low word.
  16. // The length of the string is in bytes and excludes the terminating
  17. // NULL.
  18. //
  19. // NOTE 1: This function must now handle environment variables in Quotes
  20. //
  21. // NOTE 2: There is no need for this API since NT has the equivalent APIs such
  22. // as ExpandEnvironmentStrings. But must keep it since it is a public
  23. // API in Win3.1.
  24. // Instead of doing all the work here, just call ExpandEnvironmentStrings.
  25. //-------------------------------------------------------------------------
  26. DWORD APIENTRY DoEnvironmentSubstA(
  27. LPSTR pszSrc, // The input string.
  28. UINT cchSrc) // The limit of characters in the input string inc null.
  29. {
  30. LPSTR pszExp;
  31. DWORD cchExp;
  32. BOOL fRet = FALSE;
  33. pszExp = (LPSTR)LocalAlloc(LPTR, cchSrc);
  34. if (pszExp)
  35. {
  36. cchExp = SHExpandEnvironmentStringsA(pszSrc, pszExp, cchSrc);
  37. if (cchExp)
  38. {
  39. HRESULT hr = StringCchCopyA(pszSrc, cchSrc, pszExp);
  40. if (SUCCEEDED(hr))
  41. {
  42. fRet = TRUE;
  43. }
  44. }
  45. LocalFree(pszExp);
  46. }
  47. if (fRet)
  48. return MAKELONG(cchExp,TRUE);
  49. else
  50. return MAKELONG(cchSrc,FALSE);
  51. }
  52. #ifdef UNICODE // on Win9x platform, shlunimp.c provides the implementation
  53. DWORD APIENTRY DoEnvironmentSubstW(
  54. LPWSTR pszSrc, // The input string.
  55. UINT cchSrc) // The limit of characters in the input string inc null.
  56. {
  57. LPWSTR pszExp;
  58. DWORD cchExp;
  59. BOOL fRet = FALSE;
  60. pszExp = (LPWSTR)LocalAlloc(LPTR, cchSrc * sizeof(WCHAR));
  61. if (pszExp)
  62. {
  63. cchExp = SHExpandEnvironmentStringsW(pszSrc, pszExp, cchSrc);
  64. if (cchExp)
  65. {
  66. HRESULT hr = StringCchCopyW(pszSrc, cchSrc, pszExp);
  67. if (SUCCEEDED(hr))
  68. {
  69. fRet = TRUE;
  70. }
  71. }
  72. LocalFree(pszExp);
  73. }
  74. if (fRet)
  75. return MAKELONG(cchExp,TRUE);
  76. else
  77. return MAKELONG(cchSrc,FALSE);
  78. }
  79. #endif