strnlen(3)
π strnlen(3) β the manual page, but make it bestie π
okay so real talk, this is a page from the Library Functions Manual and it's about strnlen(3). yes the 3 means it's a library function, we love a section number, slay β¨
β¨ NAME β¨
strnlen β nonstring length π
like... length, but for a nonstring. iykyk.
πΈ LIBRARY πΈ
The Standard C library β <pink>libc, -lc</pink> π«Ά
π¦ SYNOPSIS π¦
#include <string.h> // see memory.h(3head)
size_t strnlen(const char strn[], size_t n);
π§ Feature Test Macro Requirements for glibc π§
(and if you're like "what is a feature test macro" β bestie, go read feature_test_macros(7), it's right there)
strnlen():
- Since glibc 2.10:
_POSIX_C_SOURCE >= 200809L
- Before glibc 2.10:
_GNU_SOURCE
so if you're on a crusty old glibc, you need the _GNU_SOURCE glow-up. periodt.
π₯ DESCRIPTION π₯
okay so what does this thing actually do. strnlen() figures out the length of the character sequence that lives inside the array that strn points to. that's it. that's the whole job. iconic behaviour honestly π
here's the cute part: if strn contains a string, the array can have less than n elements. yes bestie, you do NOT need to pass a whole array of n bytes. she's flexible like that π
it is equivalent to this, literally character for character:
(memchr(strn, '\0', n) ?: strn + n) - strn
look at her go. one line. main character energy π
β RETURN VALUE β
strnlen() returns the number of nonnull characters in strn. that's the tea. nonnull. count 'em. done π
π ATTRIBUTES π
if you're sitting there like "what do these words even mean", pls go check attributes(7), it explains all the terms fr fr.
- Interface:
strnlen() - Attribute: Thread safety
- Value:
MT-Safe
so she's MT-Safe, which means multi-thread safe, which means you can run her in threads and she will not start drama. we love a low-conflict queen π
π STANDARDS π
POSIX.1-2008.
π« HISTORY π«
POSIX.1-2008.
(same as above. she arrived in POSIX.1-2008 and has been serving ever since π)
π SEE ALSO π
quick vibe check bestie: nothing here is deprecated or dangerous, it's just a tiny little length function. no footguns. no undefined behaviour. she's safe. she's sweet. she ate. π₯
okay that's the whole page π and for the little sign-off at the bottom: this one came from Linux man-pages 6.20, dated 2026-08-10, and it's filed under strnlen(3). so when you cite her, cite her properly πβ¨ bye bestie, go count some nonnull characters π¦
π¦ 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