wctomb(3)

✨ wctomb(3) ✨

okay bestie, gather round, because we're talking about wctomb(3) β€” that's the manual page name AND the function name, yes it's giving title drop energy πŸ’…. She lives in the Library Functions Manual, and she's part of the Standard C library (libc, link with -lc). πŸŽ€


🌸 NAME 🌸

wctomb β€” convert a wide character to a multibyte sequence πŸ’–

πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc) 🫢

πŸ¦‹ SYNOPSIS πŸ¦‹

#include <stdlib.h>

int wctomb(char *s, wchar_t wc);

πŸ’« DESCRIPTION πŸ’«

okay so here's the tea β˜•. This function has TWO whole modes depending on whether s is NULL, and honestly? main character behavior.

  • If s is not NULL: wctomb() takes the wide character wc and converts it into its multibyte representation, then stores that at the very beginning of the character array that s points to. She also updates the shift state β€” which lives in a static anonymous variable that literally only the wctomb() function itself knows about (her little secret πŸ™ˆ) β€” and then she returns the length of said multibyte representation. That means: the number of bytes written at s. ✨
  • At most MB_CUR_MAX bytes will ever be written at s. And no, she will not double-check for you β€” the programmer must ensure that there is enough room to store the multibyte sequence at s. That's on you bestie, not her 😭
  • If s is NULL: wctomb() resets that shift state (the one known only to this function) back to the initial state, and returns nonzero if the encoding has a nontrivial shift state, or zero if the encoding is stateless. 🌈

πŸ”₯ RETURN VALUE πŸ”₯

  • If s is not NULL: wctomb() returns the number of bytes that have been written to the byte array at s. But!! if wc can not be represented as a multibyte sequence (according to the current locale), she returns -1. πŸ’€
  • If s is NULL: wctomb() returns nonzero if the encoding has nontrivial shift state, or zero if the encoding is stateless. no cap. ✨

πŸ‘‘ ATTRIBUTES πŸ‘‘

for the explanation of the terms used in this section, go check out attributes(7) β€” she's the source of truth 🫢

  • Interface: wctomb()
  • Attribute: Thread safety
  • Value: MT-Unsafe race
so yeah, wctomb() is MT-Unsafe with a race situation. Not thread-safe, she said what she said πŸ’€ be careful out there.

🧚 VERSIONS 🧚

the function wcrtomb(3) provides a better interface to the same functionality. so like, she's the glow-up version. obsessed honestly. πŸ’…

⭐ STANDARDS ⭐

C11, POSIX.1-2008. certified icon behavior ✨

πŸŽ€ HISTORY πŸŽ€

POSIX.1-2001, C99. she's been around, she's got lore πŸ“œ

πŸ’œ NOTES πŸ’œ

the behavior of wctomb() depends on the LC_CTYPE category of the current locale. so locale vibes = output vibes, iykyk 🌸


🌈 SEE ALSO 🌈


and that's the whole page bestie!! 🫢 she's from Linux man-pages 6.20, dated 2026-02-08, and she will always be wctomb(3) to us πŸ’– mwah, stan a multibyte conversion function, periodt. πŸŽ€βœ¨

πŸ“¦ 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