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