strncasecmp(3)

✨ strncasecmp(3) β€” Library Functions Manual ✨

okay so bestie, gather round, because today we're talking about strncasecmp πŸ’– this is the nonstrings case-insensitive compare function, and yes the name is unhinged, no we are not changing it, it's iconic.


πŸŽ€ NAME πŸŽ€

strncasecmp β€” nonstrings case-insensitive compare πŸ’…


πŸ“š LIBRARY πŸ“š

Standard C library β€” that would be libc, -lc 🫢


🌸 SYNOPSIS 🌸

#include <strings.h>  // see memory.h(3head)

int strncasecmp(const char s1[], const char s2[], size_t n);

note the // see memory.h(3head) comment, that's not me being extra, that's literally in there πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so like, strncasecmp() is basically strcasecmp(3)'s little sibling β€” same energy, same case-ignoring agenda β€” except it does not compare more than n bytes of s1 and s2. that's it. that's the twist. n bytes, max, periodt. πŸ’–


⭐ RETURN VALUE ⭐

strncasecmp() hands you back an integer, and it's giving one of three vibes:

  • less than zero β€” s1, once you ignore case, is found to be less than s2
  • equal to zero β€” s1 matches s2
  • greater than zero β€” s1 is found to be greater than s2

no cap, that's the whole contract. πŸ”₯


πŸ’… ATTRIBUTES πŸ’…

for the explanation of what these terms even mean, go peek at attributes(7) β€” it's the lore drop you need. here's the tea for this function:

  • Interface: strncasecmp()
  • Attribute: Thread safety
  • Value: MT-Safe locale 🧚

πŸ‘‘ STANDARDS πŸ‘‘

POSIX.1-2008. that's it, she's certified. ✨


🌈 HISTORY 🌈

4.4BSD, POSIX.1-2001. a whole ancestry. πŸ’€

so strncasecmp() first appeared in 4.4BSD, back when it was declared in <string.h>. and because historical compatibility said "we must", the glibc <string.h> header file also declares these functions β€” but only if the _DEFAULT_SOURCE feature test macro is defined (or, in glibc 2.19 and earlier, _BSD_SOURCE). yes, this is a feature test macro situation, we love those for you πŸ™ˆ

and here's what the POSIX.1-2008 standard says about these functions, quoted verbatim because I'm not paraphrasing the ancestors:

When the LC_CTYPE category of the locale being used is from the POSIX locale, these functions shall behave as if the strings had been converted to lowercase and then a byte comparison performed. Otherwise, the results are unspecified.

the results are unspecified β€” that's your cue, bestie. don't build your whole personality on mashing those bytes in a weird locale. 😭


πŸ“ SEE ALSO πŸ“


okay that's the page, you ate it, you understood it, I'm so proud 🫢 this was Linux man-pages 6.20, dated 2026-08-10 β€” go forth and compare responsibly πŸ’œπŸŒŸ

πŸ“¦ 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: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms