Home

strcoll

strcoll is a function in the C standard library used to compare two null-terminated strings according to the collation order of the current locale. It is declared in string.h with the signature int strcoll(const char *s1, const char *s2). The function returns a negative value if s1 is before s2, zero if they are considered equivalent, and a positive value if s1 is after s2 within the locale’s sorting rules. The exact return value is implementation-defined beyond the sign.

Locale dependence is the defining characteristic of strcoll. The comparison uses the LC_COLLATE category of the

Locale scope and thread considerations are important. In many C libraries, the process-wide locale affects strcoll;

Related functionality includes strxfrm, which produces a transformation of a string suitable for efficient comparison, enabling

process’s
current
locale.
In
the
C
(or
POSIX)
locale,
strcoll
typically
behaves
like
strcmp,
performing
a
byte-wise
comparison.
In
other
locales,
collation
rules
may
account
for
multibyte
characters,
diacritics,
case
folding,
and
locale-specific
sorting
orders,
which
can
produce
results
that
differ
from
a
simple
character-by-character
comparison.
changing
the
locale
with
setlocale
changes
behavior
for
all
threads.
Some
environments
provide
per-thread
locales
via
additional
APIs
such
as
newlocale
and
uselocale,
which
can
be
used
to
constrain
strcoll
to
a
specific
locale
in
a
multithreaded
program.
locale-aware
sorting
by
comparing
transformed
keys
rather
than
strings
directly.
strcoll
is
primarily
used
when
a
direct,
locale-aware
string
comparison
is
needed
without
constructing
transformation
keys.