Commit c947d451 authored by Chip Turner's avatar Chip Turner Committed by woo

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
parent bc34a5a7
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include <string.h> #include <string.h>
#include <folly/Malloc.h> #include <folly/Malloc.h>
#include <folly/String.h>
#if FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK #if FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK
# include <cxxabi.h> # include <cxxabi.h>
...@@ -56,6 +55,21 @@ extern "C" int cplus_demangle_v3_callback( ...@@ -56,6 +55,21 @@ extern "C" int cplus_demangle_v3_callback(
#endif #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 { namespace folly {
#if FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK #if FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK
...@@ -105,7 +119,7 @@ size_t demangle(const char* name, char* out, size_t outSize) { ...@@ -105,7 +119,7 @@ size_t demangle(const char* name, char* out, size_t outSize) {
demangleCallback, demangleCallback,
&dbuf); &dbuf);
if (status == 0) { // failed, return original if (status == 0) { // failed, return original
return folly::strlcpy(out, name, outSize); return my_strlcpy(out, name, outSize);
} }
if (outSize != 0) { if (outSize != 0) {
*dbuf.dest = '\0'; *dbuf.dest = '\0';
...@@ -120,7 +134,7 @@ fbstring demangle(const char* name) { ...@@ -120,7 +134,7 @@ fbstring demangle(const char* name) {
} }
size_t demangle(const char* name, char* out, size_t outSize) { size_t demangle(const char* name, char* out, size_t outSize) {
return folly::strlcpy(out, name, outSize); return my_strlcpy(out, name, outSize);
} }
#endif #endif
......
...@@ -492,16 +492,6 @@ void toLowerAscii(char* str, size_t length) { ...@@ -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 { namespace detail {
size_t hexDumpLine(const void* ptr, size_t offset, size_t size, size_t hexDumpLine(const void* ptr, size_t offset, size_t size,
......
...@@ -569,9 +569,6 @@ inline void toLowerAscii(MutableStringPiece str) { ...@@ -569,9 +569,6 @@ inline void toLowerAscii(MutableStringPiece str) {
toLowerAscii(str.begin(), str.size()); toLowerAscii(str.begin(), str.size());
} }
// glibc doesn't have strlcpy
size_t strlcpy(char* dest, const char* const src, size_t size);
} // namespace folly } // namespace folly
// Hook into boost's type traits // Hook into boost's type traits
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment