diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2006-08-08 22:22:47 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2006-08-08 22:22:47 +0000 |
commit | 73742c2566e6f8d56b3b132026ad477b9924e774 (patch) | |
tree | 823ee8f3472c0901cdcc6d662a110efc4b7ea1ae /lib/xmemxfrm.c | |
parent | f2f8ea1001b4e29bba94b47f72d21f758e596288 (diff) | |
download | coreutils-73742c2566e6f8d56b3b132026ad477b9924e774.tar.xz |
New file, introduced for shuf, sort -R, and/or shred.
Diffstat (limited to 'lib/xmemxfrm.c')
-rw-r--r-- | lib/xmemxfrm.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/xmemxfrm.c b/lib/xmemxfrm.c new file mode 100644 index 000000000..6cc726a73 --- /dev/null +++ b/lib/xmemxfrm.c @@ -0,0 +1,65 @@ +/* Locale-specific memory transformation + + Copyright (C) 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert <eggert@cs.ucla.edu>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include "xmemxfrm.h" + +#include <errno.h> +#include <stdlib.h> + +#include "gettext.h" +#define _(msgid) gettext (msgid) + +#include "error.h" +#include "exitfail.h" +#include "memxfrm.h" +#include "quotearg.h" + +/* Store into DEST (of size DESTSIZE) the text in SRC (of size + SRCSIZE) transformed so that the result of memcmp on two + transformed texts (with ties going to the longer text) is the same + as the result of memcoll on the two texts before their + transformation. Perhaps temporarily modify the byte after SRC, but + restore its original contents before returning. + + Return the size of the resulting text. DEST contains an + indeterminate value if the resulting size is greater than DESTSIZE. + Report an error and exit if there is an error. */ + +size_t +xmemxfrm (char *restrict dest, size_t destsize, + char *restrict src, size_t srcsize) +{ + size_t translated_size = memxfrm (dest, destsize, src, srcsize); + + if (errno) + { + error (0, errno, _("string transformation failed")); + error (0, 0, _("Set LC_ALL='C' to work around the problem.")); + error (exit_failure, 0, + _("The untransformed string was %s."), + quotearg_n_style_mem (0, locale_quoting_style, src, srcsize)); + } + + return translated_size; +} |