Make strlcpy available in folly
[folly.git] / folly / String.cpp
index 337b7e37dac94371203e3a3894861dcdb14bfa4c..b1f0a85654e8b566db1bc85d5b2001034c9c8d56 100644 (file)
@@ -492,6 +492,16 @@ 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,