wcscspn(3)
π wcscspn(3) β bestie, let's go find some characters
okay so this is wcscspn(3), a libc wide-character girly, and she is so much simpler than she sounds. she's basically the wide-char version of strcspn(3), and once you get her whole deal you'll be obsessed, fr fr.
π LIBRARY
Standard C library (libc, -lc). yes bestie, she lives in libc, she's built in, no extra linking drama, we love a low-maintenance queen π«Ά
β¨ SYNOPSIS
#include <wchar.h>
size_t wcscspn(const wchar_t *wcs, const wchar_t *reject);
two pointers in, one size_t out. that's the whole vibe πΈ
π¦ DESCRIPTION
so here's the tea. wcscspn() is the wide-character equivalent of strcspn(3) β same energy, but for wide chars instead of regular ones.
what she does is figure out the length of the longest initial segment of wcs that consists entirely of wide characters that are not listed in reject. basically: she walks along wcs from the front, and the second she bumps into a character that's also hanging out in reject, she stops counting. π
in other words β and i want you to say this with me β she searches for the first occurrence in the wide-character string wcs of any of the characters in the wide-character string reject. that's it. that's the function. iconic behavior tbh π
real talk:rejectis a set of characters, not a substring. order inrejectdoesn't matter, duplicates don't matter, she just wants to know if the char is in there at all. π
π RETURN VALUE
she returns the number of wide characters in the longest initial segment of wcs which consists entirely of wide characters not listed in reject.
OR, if you wanna say it the other way (same thing, bestie, it's giving two outfits one girl): she returns the position of the first occurrence</> in the wide-character string wcs of any of the characters in the wide-character string reject β or wcslen(wcs) if there is none. so no match at all = you get the full length. she counted to the end and found nothing. valid. π
π₯ ATTRIBUTES
for an explanation of the terms used in this section, see attributes(7). (yes, that's a real man page, go read her, she ate)
wcscspn()β Thread safety:MT-Safeβ¨
that's it! MT-Safe, no asterisks, no caveats, no "well actually". she plays nice with threads, periodt. π
π STANDARDS
C11, POSIX.1-2008. she's certified, she's official, she's in the standards bestie. π
π HISTORY
POSIX.1-2001, C99. so she's been around since forever and she's still serving. a true veteran main character. β
π SEE ALSO
strcspn(3)β the narrow-char original, the blueprint, the motherwcspbrk(3)β finds the pointer to the first matching char instead (different girl, similar vibe)wcsspn(3)β the opposite situation: counts chars that are in the set
and that's the whole page, bestie!! go forth and span your wide chars with confidence π§ββοΈπ
sign-off time: this lil page came from Linux man-pages 6.20, dated 2026-02-08, and yeah she's still called wcscspn(3) in case you forgot already. mwah π
π
π¦ 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