summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '3rdParty/Breakpad/src/common/windows')
-rw-r--r--3rdParty/Breakpad/src/common/windows/guid_string.cc76
-rw-r--r--3rdParty/Breakpad/src/common/windows/guid_string.h58
-rw-r--r--3rdParty/Breakpad/src/common/windows/string_utils-inl.h142
3 files changed, 276 insertions, 0 deletions
diff --git a/3rdParty/Breakpad/src/common/windows/guid_string.cc b/3rdParty/Breakpad/src/common/windows/guid_string.cc
new file mode 100644
index 0000000..b7f877e
--- /dev/null
+++ b/3rdParty/Breakpad/src/common/windows/guid_string.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2006, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// guid_string.cc: Convert GUIDs to strings.
+//
+// See guid_string.h for documentation.
+
+#include <wchar.h>
+
+#include "common/windows/string_utils-inl.h"
+
+#include "common/windows/guid_string.h"
+
+namespace google_breakpad {
+
+// static
+wstring GUIDString::GUIDToWString(GUID *guid) {
+ wchar_t guid_string[37];
+ swprintf(
+ guid_string, sizeof(guid_string) / sizeof(guid_string[0]),
+ L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+ guid->Data1, guid->Data2, guid->Data3,
+ guid->Data4[0], guid->Data4[1], guid->Data4[2],
+ guid->Data4[3], guid->Data4[4], guid->Data4[5],
+ guid->Data4[6], guid->Data4[7]);
+
+ // remove when VC++7.1 is no longer supported
+ guid_string[sizeof(guid_string) / sizeof(guid_string[0]) - 1] = L'\0';
+
+ return wstring(guid_string);
+}
+
+// static
+wstring GUIDString::GUIDToSymbolServerWString(GUID *guid) {
+ wchar_t guid_string[33];
+ swprintf(
+ guid_string, sizeof(guid_string) / sizeof(guid_string[0]),
+ L"%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
+ guid->Data1, guid->Data2, guid->Data3,
+ guid->Data4[0], guid->Data4[1], guid->Data4[2],
+ guid->Data4[3], guid->Data4[4], guid->Data4[5],
+ guid->Data4[6], guid->Data4[7]);
+
+ // remove when VC++7.1 is no longer supported
+ guid_string[sizeof(guid_string) / sizeof(guid_string[0]) - 1] = L'\0';
+
+ return wstring(guid_string);
+}
+
+} // namespace google_breakpad
diff --git a/3rdParty/Breakpad/src/common/windows/guid_string.h b/3rdParty/Breakpad/src/common/windows/guid_string.h
new file mode 100644
index 0000000..f8aa8a2
--- /dev/null
+++ b/3rdParty/Breakpad/src/common/windows/guid_string.h
@@ -0,0 +1,58 @@
+// Copyright (c) 2006, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// guid_string.cc: Convert GUIDs to strings.
+
+#ifndef COMMON_WINDOWS_GUID_STRING_H__
+#define COMMON_WINDOWS_GUID_STRING_H__
+
+#include <Guiddef.h>
+
+#include <string>
+
+namespace google_breakpad {
+
+using std::wstring;
+
+class GUIDString {
+ public:
+ // Converts guid to a string in the format recommended by RFC 4122 and
+ // returns the string.
+ static wstring GUIDToWString(GUID *guid);
+
+ // Converts guid to a string formatted as uppercase hexadecimal, with
+ // no separators, and returns the string. This is the format used for
+ // symbol server identifiers, although identifiers have an age tacked
+ // on to the string.
+ static wstring GUIDToSymbolServerWString(GUID *guid);
+};
+
+} // namespace google_breakpad
+
+#endif // COMMON_WINDOWS_GUID_STRING_H__
diff --git a/3rdParty/Breakpad/src/common/windows/string_utils-inl.h b/3rdParty/Breakpad/src/common/windows/string_utils-inl.h
new file mode 100644
index 0000000..d281aaa
--- /dev/null
+++ b/3rdParty/Breakpad/src/common/windows/string_utils-inl.h
@@ -0,0 +1,142 @@
+// Copyright (c) 2006, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// string_utils-inl.h: Safer string manipulation on Windows, supporting
+// pre-MSVC8 environments.
+
+#ifndef COMMON_WINDOWS_STRING_UTILS_INL_H__
+#define COMMON_WINDOWS_STRING_UTILS_INL_H__
+
+#include <stdarg.h>
+#include <wchar.h>
+
+#include <string>
+
+// The "ll" printf format size specifier corresponding to |long long| was
+// intrudced in MSVC8. Earlier versions did not provide this size specifier,
+// but "I64" can be used to print 64-bit types. Don't use "I64" where "ll"
+// is available, in the event of oddball systems where |long long| is not
+// 64 bits wide.
+#if _MSC_VER >= 1400 // MSVC 2005/8
+#define WIN_STRING_FORMAT_LL "ll"
+#else // MSC_VER >= 1400
+#define WIN_STRING_FORMAT_LL "I64"
+#endif // MSC_VER >= 1400
+
+// A nonconforming version of swprintf, without the length argument, was
+// included with the CRT prior to MSVC8. Although a conforming version was
+// also available via an overload, it is not reliably chosen. _snwprintf
+// behaves as a standards-confirming swprintf should, so force the use of
+// _snwprintf when using older CRTs.
+#if _MSC_VER < 1400 // MSVC 2005/8
+#define swprintf _snwprintf
+#else
+// For MSVC8 and newer, swprintf_s is the recommended method. Conveniently,
+// it takes the same argument list as swprintf.
+#define swprintf swprintf_s
+#endif // MSC_VER < 1400
+
+namespace google_breakpad {
+
+using std::string;
+using std::wstring;
+
+class WindowsStringUtils {
+ public:
+ // Roughly equivalent to MSVC8's wcscpy_s, except pre-MSVC8, this does
+ // not fail if source is longer than destination_size. The destination
+ // buffer is always 0-terminated.
+ static void safe_wcscpy(wchar_t *destination, size_t destination_size,
+ const wchar_t *source);
+
+ // Roughly equivalent to MSVC8's wcsncpy_s, except that _TRUNCATE cannot
+ // be passed directly, and pre-MSVC8, this will not fail if source or count
+ // are longer than destination_size. The destination buffer is always
+ // 0-terminated.
+ static void safe_wcsncpy(wchar_t *destination, size_t destination_size,
+ const wchar_t *source, size_t count);
+
+ // Performs multi-byte to wide character conversion on C++ strings, using
+ // mbstowcs_s (MSVC8) or mbstowcs (pre-MSVC8). Returns false on failure,
+ // without setting wcs.
+ static bool safe_mbstowcs(const string &mbs, wstring *wcs);
+
+ // The inverse of safe_mbstowcs.
+ static bool safe_wcstombs(const wstring &wcs, string *mbs);
+
+ // Returns the base name of a file, e.g. strips off the path.
+ static wstring GetBaseName(const wstring &filename);
+
+ private:
+ // Disallow instantiation and other object-based operations.
+ WindowsStringUtils();
+ WindowsStringUtils(const WindowsStringUtils&);
+ ~WindowsStringUtils();
+ void operator=(const WindowsStringUtils&);
+};
+
+// static
+inline void WindowsStringUtils::safe_wcscpy(wchar_t *destination,
+ size_t destination_size,
+ const wchar_t *source) {
+#if _MSC_VER >= 1400 // MSVC 2005/8
+ wcscpy_s(destination, destination_size, source);
+#else // _MSC_VER >= 1400
+ // Pre-MSVC 2005/8 doesn't have wcscpy_s. Simulate it with wcsncpy.
+ // wcsncpy doesn't 0-terminate the destination buffer if the source string
+ // is longer than size. Ensure that the destination is 0-terminated.
+ wcsncpy(destination, source, destination_size);
+ if (destination && destination_size)
+ destination[destination_size - 1] = 0;
+#endif // _MSC_VER >= 1400
+}
+
+// static
+inline void WindowsStringUtils::safe_wcsncpy(wchar_t *destination,
+ size_t destination_size,
+ const wchar_t *source,
+ size_t count) {
+#if _MSC_VER >= 1400 // MSVC 2005/8
+ wcsncpy_s(destination, destination_size, source, count);
+#else // _MSC_VER >= 1400
+ // Pre-MSVC 2005/8 doesn't have wcsncpy_s. Simulate it with wcsncpy.
+ // wcsncpy doesn't 0-terminate the destination buffer if the source string
+ // is longer than size. Ensure that the destination is 0-terminated.
+ if (destination_size < count)
+ count = destination_size;
+
+ wcsncpy(destination, source, count);
+ if (destination && count)
+ destination[count - 1] = 0;
+#endif // _MSC_VER >= 1400
+}
+
+} // namespace google_breakpad
+
+#endif // COMMON_WINDOWS_STRING_UTILS_INL_H__