/thirdparty/breakpad/common/windows/guid_string.cc

http://github.com/tomahawk-player/tomahawk · C++ · 76 lines · 29 code · 12 blank · 35 comment · 0 complexity · d5702ee9dc9112d7132c8f83187b55ab MD5 · raw file

  1. // Copyright (c) 2006, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // guid_string.cc: Convert GUIDs to strings.
  30. //
  31. // See guid_string.h for documentation.
  32. #include <wchar.h>
  33. #include "common/windows/string_utils-inl.h"
  34. #include "common/windows/guid_string.h"
  35. namespace google_breakpad {
  36. // static
  37. wstring GUIDString::GUIDToWString(GUID *guid) {
  38. wchar_t guid_string[37];
  39. swprintf(
  40. guid_string, sizeof(guid_string) / sizeof(guid_string[0]),
  41. L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
  42. guid->Data1, guid->Data2, guid->Data3,
  43. guid->Data4[0], guid->Data4[1], guid->Data4[2],
  44. guid->Data4[3], guid->Data4[4], guid->Data4[5],
  45. guid->Data4[6], guid->Data4[7]);
  46. // remove when VC++7.1 is no longer supported
  47. guid_string[sizeof(guid_string) / sizeof(guid_string[0]) - 1] = L'\0';
  48. return wstring(guid_string);
  49. }
  50. // static
  51. wstring GUIDString::GUIDToSymbolServerWString(GUID *guid) {
  52. wchar_t guid_string[33];
  53. swprintf(
  54. guid_string, sizeof(guid_string) / sizeof(guid_string[0]),
  55. L"%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
  56. guid->Data1, guid->Data2, guid->Data3,
  57. guid->Data4[0], guid->Data4[1], guid->Data4[2],
  58. guid->Data4[3], guid->Data4[4], guid->Data4[5],
  59. guid->Data4[6], guid->Data4[7]);
  60. // remove when VC++7.1 is no longer supported
  61. guid_string[sizeof(guid_string) / sizeof(guid_string[0]) - 1] = L'\0';
  62. return wstring(guid_string);
  63. }
  64. } // namespace google_breakpad