STRCASECMP(3)
๐ 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
- Copyright (c) 1990, 1991, 1993 The Regents of the University of California. All rights reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms