aboutsummaryrefslogtreecommitdiffstats
path: root/brillo/type_name_undecorate.cc
diff options
context:
space:
mode:
authorAlex Vakulenko <avakulenko@google.com>2015-10-12 15:21:28 -0700
committerAlex Vakulenko <avakulenko@google.com>2015-10-13 16:10:03 -0700
commit9ed0cab99f18acb3570a35e9408f24355f6b8324 (patch)
tree60e3b4c2822b812b3218489a9a6d835df1e8ca6e /brillo/type_name_undecorate.cc
parenteabfe23a51c91a103042793ac2d5c28170994e1f (diff)
downloadplatform_external_libbrillo-9ed0cab99f18acb3570a35e9408f24355f6b8324.tar.gz
platform_external_libbrillo-9ed0cab99f18acb3570a35e9408f24355f6b8324.tar.bz2
platform_external_libbrillo-9ed0cab99f18acb3570a35e9408f24355f6b8324.zip
Move chromeos symbols into brillo namespace
And move the include files into "brillo" directory instead of "chromeos" BUG: 24872993 TEST=built aosp and brillo and unit tests pass on dragonoboard Change-Id: Ieb979d1ebd3152921d36cd15acbd6247f02aae69
Diffstat (limited to 'brillo/type_name_undecorate.cc')
-rw-r--r--brillo/type_name_undecorate.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/brillo/type_name_undecorate.cc b/brillo/type_name_undecorate.cc
new file mode 100644
index 0000000..9a1d6a1
--- /dev/null
+++ b/brillo/type_name_undecorate.cc
@@ -0,0 +1,33 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <brillo/type_name_undecorate.h>
+
+#ifdef __GNUG__
+#include <cstdlib>
+#include <cxxabi.h>
+#include <memory>
+#endif // __GNUG__
+
+namespace brillo {
+
+std::string UndecorateTypeName(const char* type_name) {
+#ifdef __GNUG__
+ // Under g++ use abi::__cxa_demangle() to undecorate the type name.
+ int status = 0;
+
+ std::unique_ptr<char, decltype(&std::free)> res{
+ abi::__cxa_demangle(type_name, nullptr, nullptr, &status),
+ std::free
+ };
+
+ return (status == 0) ? res.get() : type_name;
+#else
+ // If not compiled with g++, do nothing...
+ // E.g. MSVC's type_info::name() already contains undecorated name.
+ return type_name;
+#endif
+}
+
+} // namespace brillo