STRCASECMP(3P)

πŸ’– STRCASECMP(3P) β€” the POSIX Programmer's Manual, but make it a group chat πŸ’–

okay bestie, welcome to the POSIX Programmer's Manual. this page? it's strcasecmp and its little friend group. we're comparing strings but we do NOT care about case. uppercase, lowercase, whatever, we're not judging πŸ’…


🌸 PROLOG 🌸

real talk before we start: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ β€” so go consult the corresponding Linux manual page if you wanna know what Linux actually does. or, plot twist, the interface might not even be implemented on Linux at all. πŸ™ˆ


✨ NAME ✨

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

yes queen, comparisons that don't care about case. the whole squad.


πŸŽ€ 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 πŸ¦‹

so, strcasecmp() and strcasecmp_l() shall compare the string pointed to by s1 to the string pointed to by s2, while ignoring differences in case. that's the whole vibe. the case is not the moment.

and strncasecmp() and strncasecmp_l()? same energy, but they compare not more than n bytes from the string pointed to by s1 to the string pointed to by s2, still ignoring case differences. we're keeping it cute and contained.

now the locale tea β˜•:

  • strcasecmp() and strncasecmp() use the current locale to determine the case of the characters.
  • strcasecmp_l() and strncasecmp_l() use the locale represented by locale to determine 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 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. 😭 so don't come crying to me if your locale is doing its own thing.

🚨 BIG warning energy: 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. that's not a vibe. that's undefined behavior. don't do it. periodt.

πŸ‘‘ RETURN VALUE πŸ‘‘

upon completion, strcasecmp() and strcasecmp_l() shall return an integer that is greater than, equal to, or less than 0, if the string pointed to by s1 is, ignoring case, greater than, equal to, or less than the string pointed to by s2, respectively. iconic. simple. no notes.

upon successful completion, strncasecmp() and strncasecmp_l() shall return an integer that is greater than, equal to, or less than 0, if 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. same energy, n-bytes flavored. πŸ’–


πŸ’€ ERRORS πŸ’€

no errors are defined. nothing to report, we ate and left no crumbs.

the following sections are informative. iykyk.


🌈 EXAMPLES 🌈

None.

(not me showing up with zero examples. the audacity. πŸ™ˆ)


πŸ“ APPLICATION USAGE πŸ“

None.


🧚 RATIONALE 🧚

None.


⭐ FUTURE DIRECTIONS ⭐

None.


πŸ’œ SEE ALSO πŸ’œ

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

okay legal bestie, here we go, word for word, don't skip it:

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 page, bestie 🫢 β€” signed off by IEEE/The Open Group, 2017, which is the source, the version AND the date all at once, so you know exactly who's responsible for this masterpiece. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from