STRCASECMP(3)

๐Ÿ“ฆ
version 15.1 ยท 2 versions
, in freebsd 15.1

๐Ÿ’– STRCASECMP(3) โ€” the library functions manual, bestie ๐Ÿ’–

okay so this is the page for strcasecmp, strncasecmp and their locale-locale cousins, and honestly? it's giving "small but mighty". it lives in the Library Functions Manual section of the man pages, and today we're gonna get you fluent in it. no cap. โœจ


๐ŸŒธ NAME ๐ŸŒธ

strcasecmp, strncasecmp โ€” compare strings, ignoring case

like, compare two strings but you don't care about upper vs lower case. Hello and hELLo? same energy. ๐Ÿ’…

๐Ÿซถ LIBRARY ๐Ÿซถ

Standard C Library (libc, -lc) โ€” that's where these cuties live. link with -lc and you're set.

โญ SYNOPSIS โญ

so first, the classic duo:

#include <strings.h>

int
strcasecmp(const char *s1, const char *s2);

int
strncasecmp(const char *s1, const char *s2, size_t len);

then the fancy locale-aware versions, which need a second header:

#include <strings.h>
#include <xlocale.h>

int
strcasecmp_l(const char *s1, const char *s2, locale_t loc);

int
strncasecmp_l(const char *s1, const char *s2, size_t len, locale_t loc);

๐ŸŽ€ DESCRIPTION ๐ŸŽ€

so the way this works: strcasecmp() and strncasecmp() compare the null-terminated strings s1 and s2. both of them. null-terminated. you know the vibe. ๐Ÿฆ‹

strncasecmp() is the "i don't have all day" version โ€” it compares at most len characters. iconic for when you only care about the first few.

and then strcasecmp_l() and strncasecmp_l() do exactly the same thing as their non-locale versions above, except they take an explicit locale (locale_t loc) instead of using the current locale. so if you want to be all "i'm in charge of my own locale destiny", that's your move. ๐Ÿ‘‘

๐Ÿ”ฅ RETURN VALUES ๐Ÿ”ฅ

okay this part is important, listen up:

the functions strcasecmp() and strncasecmp() return an integer that is greater than, equal to, or less than 0, depending on whether s1 is lexicographically greater than, equal to, or less than s2 โ€” and that's after translation of each corresponding character to lower-case. so like, case-blind comparison, but the result still tells you the ordering. โœจ

and the strings themselves are not modified. no mutation, no drama, we just look. ๐Ÿ™ˆ

the comparison is done using unsigned characters, so that '\200' is greater than '\0'. yes bestie, that little detail matters. ๐Ÿ’€

strcasecmp_l() and strncasecmp_l() do the same, but take explicit locales.

๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

go read these too, they're all in the family:

๐ŸŒˆ HISTORY ๐ŸŒˆ

strcasecmp() and strncasecmp() first appeared in 4.4BSD. their prototypes existed previously in <string.h> before they were moved to <strings.h> for IEEE Std 1003.1-2001 ("POSIX.1") compliance. so yeah, they got relocated for the paperwork. โœจ


and that's the whole page, bestie โ€” you're officially fluent ๐Ÿ’œ

little sign-off: this one's from Debian, dated May 29, 2014, and the page itself is STRCASECMP(3). go forth and compare case-insensitively. periodt. ๐ŸŽ€๐ŸŒท
๐Ÿ“ฆ where this page comes from
  • freebsd 15.1: base 15.1
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms