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.

86 lines
1.4 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name:
  4. drstr.cpp
  5. Abstract:
  6. Misc. String Utils
  7. Author:
  8. Tad Brockway
  9. Revision History:
  10. --*/
  11. #include <precom.h>
  12. #define TRC_FILE "drstr"
  13. #include "drstr.h"
  14. #include "atrcapi.h"
  15. #include "drdbg.h"
  16. BOOL
  17. DrSetStringValue(
  18. IN OUT DRSTRING *str,
  19. IN const DRSTRING value
  20. )
  21. /*++
  22. Routine Description:
  23. Set a string value after resizing the data member.
  24. Arguments:
  25. string - String to set/resize.
  26. value - Value to set string to.
  27. Return Value:
  28. TRUE on success. Otherwise, FALSE
  29. --*/
  30. {
  31. ULONG len;
  32. BOOL ret = TRUE;
  33. HRESULT hr;
  34. DC_BEGIN_FN("DrSetStringValue");
  35. //
  36. // Release the current name.
  37. //
  38. if (*str != NULL) {
  39. delete *str;
  40. }
  41. //
  42. // Allocate the new name.
  43. //
  44. if (value != NULL) {
  45. len = (STRLEN(value) + 1);
  46. *str = new TCHAR[len];
  47. if (*str != NULL) {
  48. hr = StringCchCopy(*str, len, value);
  49. TRC_ASSERT(SUCCEEDED(hr),
  50. (TB,_T("Str copy for long string failed: 0x%x"),hr));
  51. }
  52. else {
  53. TRC_ERR((TB, _T("Can't allocate %ld bytes for string."), len));
  54. ret = FALSE;
  55. }
  56. }
  57. else {
  58. *str = NULL;
  59. }
  60. DC_END_FN();
  61. return ret;
  62. }