Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

strcoll(3C)

Name

strcoll, strcoll_l - string collation

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

The strcoll() and strcoll_l() functions compare the string pointed to by s1 to the string pointed to by s2. For strcoll(), both strings are interpreted as appropriate to the LC_COLLATE category of the current locale. For strcoll_l(), both strings are interpreted as appropriate to the LC_COLLATE category of the locale represented by locale.

The strcoll() and strcoll_l() functions do not change the setting of errno if successful.

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.

The behavior is undefined if the locale argument to strcoll_l() is the special locale object LC_GLOBAL_LOCALE or is not a valid locale object handle.

Return Values

Upon successful completion, strcoll() and strcoll_l() return an integer greater than, equal to, or less than zero in direct correlation to whether string s1 is greater than, equal to, or less than the string s2. The comparison is based on strings interpreted as appropriate to the current locale or locale represented by locale respectively, for category LC_COLLATE (see setlocale(3C)).

On error, strcoll() and strcoll_l() may set errno, but no return value is reserved to indicate an error.

Usage

Both strcoll() and strxfrm(3C) provide for locale-specific string sorting. strcoll() is intended for applications in which the number of comparisons per string is small. When strings are to be compared a number of times, strxfrm(3C) is a more appropriate function because the transformation process occurs only once. The same applies between strcoll_l() and strxfrm_l(3C).

Errors

The strcoll() and strcoll_l() functions may fail if:

EINVAL

The s1 or s2 arguments contain characters outside the domain of the collating sequence.

Files

/usr/lib/locale/locale/locale.so.*

LC_COLLATE database for locale

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
CSI
Enabled
Interface Stability
Committed
MT-Level
MT-Safe
Standard

See Also

localedef(1), duplocale(3C), freelocale(3C), newlocale(3C), setlocale(3C), strcmp(3C), string(3C), strxfrm(3C), wcscoll(3C), wcsxfrm(3C), u8_strcmp(3C), uselocale(3C), attributes(7), environ(7), standards(7)

Handling Characters and Character Strings in Internationalizing and Localizing Applications in Oracle Solaris

History

The strcoll_l() function was added to Oracle Solaris in the Solaris 11.4.0 release.

The strcoll() function has been included in Solaris since the Solaris 2.0 release.