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.

106 lines
1.5 KiB

  1. /*++
  2. Copyright (c) 1990-1998 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. util.c
  6. // @@BEGIN_DDKSPLIT
  7. Abstract:
  8. Environment:
  9. User Mode -Win32
  10. NOTE: THIS IS FOR THE DDK ONLY!
  11. Revision History:
  12. // @@END_DDKSPLIT
  13. --*/
  14. #include "local.h"
  15. LPVOID
  16. ReallocSplMem(
  17. LPVOID pOldMem,
  18. DWORD cbOld,
  19. DWORD cbNew
  20. )
  21. {
  22. LPVOID pNewMem;
  23. pNewMem=AllocSplMem(cbNew);
  24. if (pOldMem && pNewMem) {
  25. if (cbOld) {
  26. CopyMemory( pNewMem, pOldMem, min(cbNew, cbOld));
  27. }
  28. FreeSplMem(pOldMem);
  29. }
  30. return pNewMem;
  31. }
  32. LPWSTR
  33. AllocSplStr(
  34. LPWSTR pStr
  35. )
  36. /*++
  37. Routine Description:
  38. This function will allocate enough local memory to store the specified
  39. string, and copy that string to the allocated memory
  40. Arguments:
  41. pStr - Pointer to the string that needs to be allocated and stored
  42. Return Value:
  43. NON-NULL - A pointer to the allocated memory containing the string
  44. FALSE/NULL - The operation failed. Extended error status is available
  45. using GetLastError.
  46. --*/
  47. {
  48. LPWSTR pMem;
  49. DWORD cbStr;
  50. if (!pStr) {
  51. return NULL;
  52. }
  53. cbStr = wcslen(pStr)*sizeof(WCHAR) + sizeof(WCHAR);
  54. if (pMem = AllocSplMem( cbStr )) {
  55. CopyMemory( pMem, pStr, cbStr );
  56. }
  57. return pMem;
  58. }
  59. LPVOID
  60. AllocSplMem(
  61. DWORD cbAlloc
  62. )
  63. {
  64. PVOID pvMemory;
  65. pvMemory = GlobalAlloc(GMEM_FIXED, cbAlloc);
  66. if( pvMemory ){
  67. ZeroMemory( pvMemory, cbAlloc );
  68. }
  69. return pvMemory;
  70. }