Source code of Windows XP (NT5)
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.

82 lines
2.8 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. StrCpyA(pszSrc, pszExp);
  40. fRet = TRUE;
  41. }
  42. LocalFree(pszExp);
  43. }
  44. if (fRet)
  45. return MAKELONG(cchExp,TRUE);
  46. else
  47. return MAKELONG(cchSrc,FALSE);
  48. }
  49. #ifdef UNICODE // on Win9x platform, shlunimp.c provides the implementation
  50. DWORD APIENTRY DoEnvironmentSubstW(
  51. LPWSTR pszSrc, // The input string.
  52. UINT cchSrc) // The limit of characters in the input string inc null.
  53. {
  54. LPWSTR pszExp;
  55. DWORD cchExp;
  56. BOOL fRet = FALSE;
  57. pszExp = (LPWSTR)LocalAlloc(LPTR, cchSrc * sizeof(WCHAR));
  58. if (pszExp)
  59. {
  60. cchExp = SHExpandEnvironmentStringsW(pszSrc, pszExp, cchSrc);
  61. if (cchExp)
  62. {
  63. StrCpyW(pszSrc, pszExp);
  64. fRet = TRUE;
  65. }
  66. LocalFree(pszExp);
  67. }
  68. if (fRet)
  69. return MAKELONG(cchExp,TRUE);
  70. else
  71. return MAKELONG(cchSrc,FALSE);
  72. }
  73. #endif