seq no longer mishandles cases like "seq 0 0.000001 0.000003",
[coreutils/ericb.git] / lib / xmemxfrm.c
blob8150334cde23dd4ed0ff4c681423050276b1830d
1 /* Locale-specific memory transformation
3 Copyright (C) 2006 Free Software Foundation, Inc.
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 2, or (at your option)
8 any later version.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /* Written by Paul Eggert <eggert@cs.ucla.edu>. */
21 #include <config.h>
23 #include "xmemxfrm.h"
25 #include <errno.h>
26 #include <stdlib.h>
28 #include "gettext.h"
29 #define _(msgid) gettext (msgid)
31 #include "error.h"
32 #include "exitfail.h"
33 #include "memxfrm.h"
34 #include "quotearg.h"
36 /* Store into DEST (of size DESTSIZE) the text in SRC (of size
37 SRCSIZE) transformed so that the result of memcmp on two
38 transformed texts (with ties going to the longer text) is the same
39 as the result of memcoll on the two texts before their
40 transformation. Perhaps temporarily modify the byte after SRC, but
41 restore its original contents before returning.
43 Return the size of the resulting text. DEST contains an
44 indeterminate value if the resulting size is greater than DESTSIZE.
45 Report an error and exit if there is an error. */
47 size_t
48 xmemxfrm (char *restrict dest, size_t destsize,
49 char *restrict src, size_t srcsize)
51 size_t translated_size = memxfrm (dest, destsize, src, srcsize);
53 if (errno)
55 error (0, errno, _("string transformation failed"));
56 error (0, 0, _("Set LC_ALL='C' to work around the problem."));
57 error (exit_failure, 0,
58 _("The untransformed string was %s."),
59 quotearg_n_style_mem (0, locale_quoting_style, src, srcsize));
62 return translated_size;