STRCASECMP(3POSIX)

πŸ’– STRCASECMP πŸ’– (that's the POSIX Programmer's Manual version, bestie)

okay so quick lil vibe check before we even start: this page lives in the POSIX Programmer's Manual, which means the Linux version of this interface might be different (so go peek at the Linux man page for the tea on Linux behavior), or honestly the interface might not even be implemented on Linux at all. πŸ™ˆ Keep that in mind, gorgeous.


✨ NAME ✨

strcasecmp, strcasecmp_l, strncasecmp, strncasecmp_l β€” case-insensitive string comparisons

so basically: compare strings but pretend the caps lock key doesn't exist πŸ’…


🌸 SYNOPSIS 🌸

#include <strings.h>

int strcasecmp(const char *s1, const char *s2);
int strcasecmp_l(const char *s1, const char *s2,
    locale_t locale);
int strncasecmp(const char *s1, const char *s2, size_t n);
int strncasecmp_l(const char *s1, const char *s2,
    size_t n, locale_t locale);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the plot:

strcasecmp() and strcasecmp_l() shall compare β€” while ignoring differences in case β€” the string pointed to by s1 to the string pointed to by s2.

Meanwhile strncasecmp() and strncasecmp_l() shall compare β€” again, ignoring case β€” not more than n bytes from the string pointed to by s1 to the string pointed to by s2. So like, a little sneak peek of a comparison, not the whole thing. πŸŽ€

Now the locale lore:

  • strcasecmp() and strncasecmp() use the current locale to figure out the case of the characters.
  • strcasecmp_l() and strncasecmp_l() use the locale represented by locale to figure out the case of the characters.

And here's the part where you gotta pay attention, bestie: when the LC_CTYPE category of the locale being used comes 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. 😭 so don't come crying to me about what happens outside POSIX locale, the standard literally said "idk, unspecified."

🚨 Also: the behavior is undefined if the locale argument to strcasecmp_l() or strncasecmp_l() is the special locale object LC_GLOBAL_LOCALE, or if it's not a valid locale object handle. Not valid = not your moment. Don't do it.

πŸ‘‘ RETURN VALUE πŸ‘‘

Upon completion, strcasecmp() and strcasecmp_l() shall return an integer that is greater than, equal to, or less than 0, depending on whether the string pointed to by s1 is β€” ignoring case β€” greater than, equal to, or less than the string pointed to by s2. Respectively, obviously. πŸ’…

Upon successful completion, strncasecmp() and strncasecmp_l() shall return an integer that is greater than, equal to, or less than 0, depending on whether the possibly null-terminated array pointed to by s1 is β€” ignoring case β€” greater than, equal to, or less than the possibly null-terminated array pointed to by s2. Respectively. ✨


πŸ’€ ERRORS πŸ’€

No errors are defined.

(iconic behavior honestly, nothing to report, no drama. 🫢)

The following sections are informative.


🌈 EXAMPLES 🌈

None.


πŸ’œ APPLICATION USAGE πŸ’œ

None.


🧚 RATIONALE 🧚

None.


⭐ FUTURE DIRECTIONS ⭐

None.


πŸ”₯ SEE ALSO πŸ”₯

  • wcscasecmp()
  • The Base Definitions volume of POSIX.1‐2017, <strings.h>

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page bestie, we ate and left no crumbs πŸ’…βœ¨

this cutie came to you from the POSIX Programmer's Manual, courtesy of IEEE / The Open Group, dated 2017 β€” and yeah the footer is still out here being all STRCASECMP(3POSIX) like it's subtle. mwah. 🫢🌸