diff options
| author | Uzair Nawaz <uzairnawaz@google.com> | 2025-07-24 11:29:40 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-24 11:29:40 -0700 |
| commit | f26c0d00df97c3b3ffce1047e92acfcbc680845b (patch) | |
| tree | dd7ed4f046cd703af50b12b1439ff924e73d1b0e /libc/src/string | |
| parent | 4f2686e5a131094d985677591482508586f1f5c9 (diff) | |
[libc] Implemented wcsdup libc function (#150453)
Implemented wcsdup by templating internal strdup function
Diffstat (limited to 'libc/src/string')
| -rw-r--r-- | libc/src/string/allocating_string_utils.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/libc/src/string/allocating_string_utils.h b/libc/src/string/allocating_string_utils.h index 1dece510e796..e2f61f77b0c7 100644 --- a/libc/src/string/allocating_string_utils.h +++ b/libc/src/string/allocating_string_utils.h @@ -20,15 +20,15 @@ namespace LIBC_NAMESPACE_DECL { namespace internal { -LIBC_INLINE cpp::optional<char *> strdup(const char *src) { +template <typename T> LIBC_INLINE cpp::optional<T *> strdup(const T *src) { if (src == nullptr) return cpp::nullopt; size_t len = string_length(src) + 1; AllocChecker ac; - char *newstr = new (ac) char[len]; + T *newstr = new (ac) T[len]; if (!ac) return cpp::nullopt; - inline_memcpy(newstr, src, len); + inline_memcpy(newstr, src, len * sizeof(T)); return newstr; } |
