wcsdup(3)

✨ wcsdup(3) ✨

okay bestie, so this is <wchar.h>'s resident copycat β€” the wide-character glow-up of strdup(3). πŸ’–

🌸 NAME 🌸

wcsdup β€” duplicate a wide-character string πŸ¦‹

πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc) β€” the O.G. one you already link against, no cap.

✨ SYNOPSIS ✨

#include <wchar.h>

wchar_t *wcsdup(const wchar_t *s);

πŸŽ€ Feature Test Macro Requirements for glibc (see feature_test_macros(7)) πŸŽ€

wcsdup():

  • Since glibc 2.10:
    • _POSIX_C_SOURCE >= 200809L
  • Before glibc 2.10:
    • _GNU_SOURCE
Like, if you're on ancient glibc and this won't compile, it's giving "you forgot _GNU_SOURCE". iykyk πŸ’…

πŸ’– DESCRIPTION πŸ’–

The wcsdup() function is literally the wide-character equivalent of the strdup(3) function β€” same vibe, wider chars. It allocates and returns a new wide-character string whose initial contents is a duplicate of the wide-character string pointed to by s. 🫢

Memory for the new wide-character string is obtained with malloc(3), and should be freed with free(3). No leaking, bestie β€” that's not the main character energy we're going for. 🧚

🚨 reminder: it's malloc'd, so it's yours. free(3) it when you're done or it's just gonna sit there in your heap forever like an unread group chat. 😭

🌈 RETURN VALUE 🌈

On success, wcsdup() returns a pointer to the new wide-character string. Slay.

On error, it returns NULL, with errno set to indicate the error. Check it. Please. πŸ™ˆ

πŸ’€ ERRORS πŸ’€

  • ENOMEM β€” Insufficient memory available to allocate duplicate string. The malloc said no. πŸ’”

πŸ‘‘ ATTRIBUTES πŸ‘‘

For an explanation of the terms used in this section, see attributes(7).

  • wcsdup() β€” Thread safety: MT-Safe βœ…
Thread safe babyyy, MT-Safe, you can call it from multiple threads and it will simply not be the drama. πŸ”₯

⭐ STANDARDS ⭐

POSIX.1-2008. Periodt. Certified. πŸ“œ

πŸ•°οΈ HISTORY πŸ•°οΈ

libc5, glibc 2.0 β€” so it's been here since basically forever, an icon, a legend. πŸ‘‘


πŸ”Ž SEE ALSO πŸ”Ž


k bye, love u, go free your strings 🫢 β€” this page came to you from Linux man-pages 6.20, dated 2026-02-08, and it's wcsdup(3) fr fr. πŸ’œβœ¨

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: GPL-2.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms