Line data Source code
1 : /* Locale-specific memory transformation
2 :
3 : Copyright (C) 2006 Free Software Foundation, Inc.
4 :
5 : This program is free software: you can redistribute it and/or modify
6 : it under the terms of the GNU General Public License as published by
7 : the Free Software Foundation, either version 3 of the License, or
8 : (at your option) any later version.
9 :
10 : This program is distributed in the hope that it will be useful,
11 : but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 : GNU General Public License for more details.
14 :
15 : You should have received a copy of the GNU General Public License
16 : along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 :
18 : /* Written by Paul Eggert <eggert@cs.ucla.edu>. */
19 :
20 : #include <config.h>
21 :
22 : #include "xmemxfrm.h"
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 "memxfrm.h"
33 : #include "quotearg.h"
34 :
35 : /* Store into DEST (of size DESTSIZE) the text in SRC (of size
36 : SRCSIZE) transformed so that the result of memcmp on two
37 : transformed texts (with ties going to the longer text) is the same
38 : as the result of memcoll on the two texts before their
39 : transformation. Perhaps temporarily modify the byte after SRC, but
40 : restore its original contents before returning.
41 :
42 : Return the size of the resulting text. DEST contains an
43 : indeterminate value if the resulting size is greater than DESTSIZE.
44 : Report an error and exit if there is an error. */
45 :
46 : size_t
47 0 : xmemxfrm (char *restrict dest, size_t destsize,
48 : char *restrict src, size_t srcsize)
49 : {
50 0 : size_t translated_size = memxfrm (dest, destsize, src, srcsize);
51 :
52 0 : if (errno)
53 : {
54 0 : error (0, errno, _("string transformation failed"));
55 0 : error (0, 0, _("Set LC_ALL='C' to work around the problem."));
56 0 : error (exit_failure, 0,
57 : _("The untransformed string was %s."),
58 : quotearg_n_style_mem (0, locale_quoting_style, src, srcsize));
59 : }
60 :
61 0 : return translated_size;
62 : }
|