From c947d451ab60011477ee6e08f7ee2ff2024d437d Mon Sep 17 00:00:00 2001 From: Chip Turner Date: Fri, 22 May 2015 17:48:35 -0700 Subject: [PATCH] Revert "Make strlcpy available in folly" (D2062632) Summary: Reverting diff to fix the build. Test Plan: contbuild rule that failed to build is okay now Reviewed By: ldbrandy@fb.com --- folly/Demangle.cpp | 20 +++++++++++++++++--- folly/String.cpp | 10 ---------- folly/String.h | 3 --- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/folly/Demangle.cpp b/folly/Demangle.cpp index b6cadfe7..ee587268 100644 --- a/folly/Demangle.cpp +++ b/folly/Demangle.cpp @@ -20,7 +20,6 @@ #include #include -#include #if FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK # include @@ -56,6 +55,21 @@ extern "C" int cplus_demangle_v3_callback( #endif +namespace { + +// glibc doesn't have strlcpy +size_t my_strlcpy(char* dest, const char* src, size_t size) { + size_t len = strlen(src); + if (size != 0) { + size_t n = std::min(len, size - 1); // always null terminate! + memcpy(dest, src, n); + dest[n] = '\0'; + } + return len; +} + +} // namespace + namespace folly { #if FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK @@ -105,7 +119,7 @@ size_t demangle(const char* name, char* out, size_t outSize) { demangleCallback, &dbuf); if (status == 0) { // failed, return original - return folly::strlcpy(out, name, outSize); + return my_strlcpy(out, name, outSize); } if (outSize != 0) { *dbuf.dest = '\0'; @@ -120,7 +134,7 @@ fbstring demangle(const char* name) { } size_t demangle(const char* name, char* out, size_t outSize) { - return folly::strlcpy(out, name, outSize); + return my_strlcpy(out, name, outSize); } #endif diff --git a/folly/String.cpp b/folly/String.cpp index b1f0a856..337b7e37 100644 --- a/folly/String.cpp +++ b/folly/String.cpp @@ -492,16 +492,6 @@ void toLowerAscii(char* str, size_t length) { } } -size_t strlcpy(char* dest, const char* const src, size_t size) { - size_t len = strlen(src); - if (size != 0) { - size_t n = std::min(len, size - 1); // always null terminate! - memcpy(dest, src, n); - dest[n] = '\0'; - } - return len; -} - namespace detail { size_t hexDumpLine(const void* ptr, size_t offset, size_t size, diff --git a/folly/String.h b/folly/String.h index 9ce4be65..ef0ef3f6 100644 --- a/folly/String.h +++ b/folly/String.h @@ -569,9 +569,6 @@ inline void toLowerAscii(MutableStringPiece str) { toLowerAscii(str.begin(), str.size()); } -// glibc doesn't have strlcpy -size_t strlcpy(char* dest, const char* const src, size_t size); - } // namespace folly // Hook into boost's type traits -- 2.34.1