strcoll(3)

๐Ÿ’– strcoll(3) โ€” the man page bestie edition ๐Ÿ’–

okay so real talk, this is strcoll from the Library Functions Manual, and if you've ever sorted a list and gotten vibes-based order that doesn't match your alphabet, this function is why. let's get into it ๐Ÿฆ‹


โœจ NAME โœจ

strcoll โ€” strings LC_COLLATE compare

like, it literally compares strings, but culturally. it's giving "I know what order your language actually wants" ๐Ÿ’…


๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library (libc, -lc)

so you already have it, bestie. no extra install. periodt.


๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <string.h>

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

two strings walk in, one int walks out. iconic behaviour honestly.


๐Ÿ‘‘ DESCRIPTION ๐Ÿ‘‘

The strcoll() function compares the two strings s1 and s2. It returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2.

here's the tea though: the comparison is based on strings interpreted as appropriate for the program's current locale for category LC_COLLATE. so it's not comparing raw byte values like some feral gremlin โ€” it's asking "in this locale, what order do these actually go in?" ๐Ÿงš

(peep setlocale(3) for how you set that locale in the first place.)


๐Ÿ’ซ RETURN VALUE ๐Ÿ’ซ

The strcoll() function returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2, when both are interpreted as appropriate for the current locale.

so like:

  • < 0 โ†’ s1 comes first, no cap
  • 0 โ†’ they're the same, twin behaviour
  • > 0 โ†’ s1 comes after, sorry babes

๐ŸŽ€ ATTRIBUTES ๐ŸŽ€

for an explanation of the terms used in this section, go see attributes(7). here's the rundown:

  • Interface: strcoll()
  • Attribute: Thread safety
  • Value: MT-Safe locale

translation? it's thread safe but the locale part matters โ€” locale is shared state, so don't be chaotic about switching it mid-flight ๐Ÿ™ˆ


๐ŸŒˆ STANDARDS ๐ŸŒˆ

C11, POSIX.1-2008.

it's been standardised for AGES. certified, not a random hack. โœ…


๐Ÿ’œ HISTORY ๐Ÿ’œ

POSIX.1-2001, C89, SVr4, 4.3BSD.

this function is old enough to have lore. it was doing locale-aware sorting before it was cool ๐Ÿ”ฅ


๐Ÿ“ NOTES ๐Ÿ“

In the POSIX or C locales, strcoll() is equivalent to strcmp(3).

yep โ€” in those locales there's no fancy collation going on, so it's basically just strcmp wearing a little costume. cute but true ๐Ÿ’€


๐Ÿซถ SEE ALSO ๐Ÿซถ


and that's the whole page bestie!! ๐Ÿ’– this was Linux man-pages 6.20, dated 2026-08-10 โ€” go forth and sort your strings the culturally correct way. slay, stay locale-aware, and don't forget to setlocale(3) first or you're gonna have a bad time ๐Ÿ˜ญโœจ

๐Ÿ“ฆ where this page comes from
  • 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 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms