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
11
13 strcoll, strcoll_l — string comparison using collating information
14
16 #include <string.h>
17
18 int strcoll(const char *s1, const char *s2);
19 int strcoll_l(const char *s1, const char *s2,
20 locale_t locale);
21
23 For strcoll(): The functionality described on this reference page is
24 aligned with the ISO C standard. Any conflict between the requirements
25 described here and the ISO C standard is unintentional. This volume of
26 POSIX.1‐2008 defers to the ISO C standard.
27
28 The strcoll() and strcoll_l() functions shall compare the string
29 pointed to by s1 to the string pointed to by s2, both interpreted as
30 appropriate to the LC_COLLATE category of the current locale, or of the
31 locale represented by locale, respectively.
32
33 The strcoll() and strcoll_l() functions shall not change the setting of
34 errno if successful.
35
36 Since no return value is reserved to indicate an error, an application
37 wishing to check for error situations should set errno to 0, then call
38 strcoll(), or strcoll_l() then check errno.
39
40 The behavior is undefined if the locale argument to strcoll_l() is the
41 special locale object LC_GLOBAL_LOCALE or is not a valid locale object
42 handle.
43
45 Upon successful completion, strcoll() shall return an integer greater
46 than, equal to, or less than 0, according to whether the string pointed
47 to by s1 is greater than, equal to, or less than the string pointed to
48 by s2 when both are interpreted as appropriate to the current locale.
49 On error, strcoll() may set errno, but no return value is reserved to
50 indicate an error.
51
52 Upon successful completion, strcoll_l() shall return an integer greater
53 than, equal to, or less than 0, according to whether the string pointed
54 to by s1 is greater than, equal to, or less than the string pointed to
55 by s2 when both are interpreted as appropriate to the locale repre‐
56 sented by locale. On error, strcoll_l() may set errno, but no return
57 value is reserved to indicate an error.
58
60 These functions may fail if:
61
62 EINVAL The s1 or s2 arguments contain characters outside the domain of
63 the collating sequence.
64
65 The following sections are informative.
66
68 Comparing Nodes
69 The following example uses an application-defined function, node_com‐
70 pare(), to compare two nodes based on an alphabetical ordering of the
71 string field.
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‐2008, <string.h>
101
103 Portions of this text are reprinted and reproduced in electronic form
104 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
105 -- Portable Operating System Interface (POSIX), The Open Group Base
106 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
107 cal and Electronics Engineers, Inc and The Open Group. (This is
108 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
109 event of any discrepancy between this version and the original IEEE and
110 The Open Group Standard, the original IEEE and The Open Group Standard
111 is the referee document. The original Standard can be obtained online
112 at http://www.unix.org/online.html .
113
114 Any typographical or formatting errors that appear in this page are
115 most likely to have been introduced during the conversion of the source
116 files to man page format. To report such errors, see https://www.ker‐
117 nel.org/doc/man-pages/reporting_bugs.html .
118
119
120
121IEEE/The Open Group 2013 STRCOLL(3P)