1STRCOLL(3P) POSIX Programmer's Manual STRCOLL(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 strcoll, strcoll_l — string comparison using collating information
13
15 #include <string.h>
16
17 int strcoll(const char *s1, const char *s2);
18 int strcoll_l(const char *s1, const char *s2,
19 locale_t locale);
20
22 For strcoll(): The functionality described on this reference page is
23 aligned with the ISO C standard. Any conflict between the requirements
24 described here and the ISO C standard is unintentional. This volume of
25 POSIX.1‐2017 defers to the ISO C standard.
26
27 The strcoll() and strcoll_l() functions shall compare the string
28 pointed to by s1 to the string pointed to by s2, both interpreted as
29 appropriate to the LC_COLLATE category of the current locale, or of the
30 locale represented by locale, respectively.
31
32 The strcoll() and strcoll_l() functions shall not change the setting of
33 errno if successful.
34
35 Since no return value is reserved to indicate an error, an application
36 wishing to check for error situations should set errno to 0, then call
37 strcoll(), or strcoll_l() then check errno.
38
39 The behavior is undefined if the locale argument to strcoll_l() is the
40 special locale object LC_GLOBAL_LOCALE or is not a valid locale object
41 handle.
42
44 Upon successful completion, strcoll() shall return an integer greater
45 than, equal to, or less than 0, according to whether the string pointed
46 to by s1 is greater than, equal to, or less than the string pointed to
47 by s2 when both are interpreted as appropriate to the current locale.
48 On error, strcoll() may set errno, but no return value is reserved to
49 indicate an error.
50
51 Upon successful completion, strcoll_l() shall return an integer greater
52 than, equal to, or less than 0, according to whether the string pointed
53 to by s1 is greater than, equal to, or less than the string pointed to
54 by s2 when both are interpreted as appropriate to the locale repre‐
55 sented by locale. On error, strcoll_l() may set errno, but no return
56 value is reserved to indicate an error.
57
59 These functions may fail if:
60
61 EINVAL The s1 or s2 arguments contain characters outside the domain of
62 the collating sequence.
63
64 The following sections are informative.
65
67 Comparing Nodes
68 The following example uses an application-defined function, node_com‐
69 pare(), to compare two nodes based on an alphabetical ordering of the
70 string field.
71
72
73 #include <string.h>
74 ...
75 struct node { /* These are stored in the table. */
76 char *string;
77 int length;
78 };
79 ...
80 int node_compare(const void *node1, const void *node2)
81 {
82 return strcoll(((const struct node *)node1)->string,
83 ((const struct node *)node2)->string);
84 }
85 ...
86
88 The strxfrm() and strcmp() functions should be used for sorting large
89 lists.
90
92 None.
93
95 None.
96
98 alphasort(), strcmp(), strxfrm()
99
100 The Base Definitions volume of POSIX.1‐2017, <string.h>
101
103 Portions of this text are reprinted and reproduced in electronic form
104 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
105 table Operating System Interface (POSIX), The Open Group Base Specifi‐
106 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
107 Electrical and Electronics Engineers, Inc and The Open Group. In the
108 event of any discrepancy between this version and the original IEEE and
109 The Open Group Standard, the original IEEE and The Open Group Standard
110 is the referee document. The original Standard can be obtained online
111 at http://www.opengroup.org/unix/online.html .
112
113 Any typographical or formatting errors that appear in this page are
114 most likely to have been introduced during the conversion of the source
115 files to man page format. To report such errors, see https://www.ker‐
116 nel.org/doc/man-pages/reporting_bugs.html .
117
118
119
120IEEE/The Open Group 2017 STRCOLL(3P)