STRCOLL(3P)
β¨ STRCOLL(3P) β POSIX Programmer's Manual β¨
okay bestie sit down, we're doing locale-aware string comparison today and it's genuinely giving π
πΈ PROLOG πΈ
This manual page is part of the POSIX Programmer's Manual. Heads up though: the Linux implementation of this interface may differ (so like, consult the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may not even be implemented on Linux at all. π
π NAME π
strcoll, strcoll_l β string comparison using collating information
π¦ SYNOPSIS π¦
#include <string.h>
int strcoll(const char *s1, const char *s2);
int strcoll_l(const char *s1, const char *s2,
locale_t locale);
π DESCRIPTION π
For strcoll(): the functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional β nobody's trying to start drama. This volume of POSIX.1β2017 defers to the ISO C standard, periodt.
The strcoll() and strcoll_l() functions shall compare the string pointed to by s1 to the string pointed to by s2, both interpreted as appropriate to the LC_COLLATE category of the current locale, or of the locale represented by locale, respectively. So like, same job, but one of them lets you pick which locale is doing the judging. π
The strcoll() and strcoll_l() functions shall not change the setting of errno if successful. no cap.
Since no return value is reserved to indicate an error, an application wishing to check for error situations should set errno to 0, then call strcoll(), or strcoll_l() then check errno. That's the move, bestie β set it, call it, check it. π§
The behavior is undefined if the locale argument tostrcoll_l()is the special locale objectLC_GLOBAL_LOCALEor is not a valid locale object handle. literally do not do this, it's giving chaos π
β RETURN VALUE β
Upon successful completion, strcoll() shall return an integer greater than, equal to, or less than 0, according to whether the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2 when both are interpreted as appropriate to the current locale. On error, strcoll() may set errno, but no return value is reserved to indicate an error.
Upon successful completion, strcoll_l() shall return an integer greater than, equal to, or less than 0, according to whether the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2 when both are interpreted as appropriate to the locale represented by locale. On error, strcoll_l() may set errno, but no return value is reserved to indicate an error.
π₯ ERRORS π₯
These functions may fail if:
EINVALβ The s1 or s2 arguments contain characters outside the domain of the collating sequence. like they wandered off the map fr fr πΊοΈ
The following sections are informative.
π EXAMPLES π
π Comparing Nodes
The following example uses an application-defined function, node_compare(), to compare two nodes based on an alphabetical ordering of the string field.
#include <string.h>
...
struct node { /* These are stored in the table. */
char *string;
int length;
};
...
int node_compare(const void *node1, const void *node2)
{
return strcoll(((const struct node *)node1)->string,
((const struct node *)node2)->string);
}
...
π APPLICATION USAGE π
The strxfrm() and strcmp() functions should be used for sorting large lists. (iykyk β strcoll is cute for a quick compare, but for the big sort energy you want those two. β¨)
π«Ά RATIONALE π«Ά
None.
π§ FUTURE DIRECTIONS π§
None.
π SEE ALSO π
alphasort(), strcmp(), strxfrm()
The Base Definitions volume of POSIX.1β2017, <string.h>
π COPYRIGHT π
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 π thanks for reading all the way through, mwah π this one came to you from IEEE/The Open Group, dated 2017 β stay collated, stay iconic, and remember: if the string compares funny, it's probably the locale's fault, not yours. π β¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- 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-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms