]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/gnu-sort/lib/xmemcoll.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / gnu-sort / lib / xmemcoll.c
1 /* Locale-specific memory comparison.
2    Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17
18 /* Contributed by Paul Eggert <eggert@twinsun.com>.  */
19
20 #if HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <errno.h>
25 #include <stdlib.h>
26
27 #include "gettext.h"
28 #define _(msgid) gettext (msgid)
29
30 #include "error.h"
31 #include "exitfail.h"
32 #include "memcoll.h"
33 #include "quotearg.h"
34 #include "xmemcoll.h"
35
36 /* Compare S1 (with length S1LEN) and S2 (with length S2LEN) according
37    to the LC_COLLATE locale.  S1 and S2 do not overlap, and are not
38    adjacent.  Temporarily modify the bytes after S1 and S2, but
39    restore their original contents before returning.  Report an error
40    and exit if there is an error.  */
41
42 int
43 xmemcoll (char *s1, size_t s1len, char *s2, size_t s2len)
44 {
45   int diff = memcoll (s1, s1len, s2, s2len);
46   int collation_errno = errno;
47
48   if (collation_errno)
49     {
50       error (0, collation_errno, _("string comparison failed"));
51       error (0, 0, _("Set LC_ALL='C' to work around the problem."));
52       error (exit_failure, 0,
53              _("The strings compared were %s and %s."),
54              quotearg_n_style_mem (0, locale_quoting_style, s1, s1len),
55              quotearg_n_style_mem (1, locale_quoting_style, s2, s2len));
56     }
57
58   return diff;
59 }