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 thans2 - equal to zero β
s1matchess2 - greater than zero β
s1is found to be greater thans2
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
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms