1 --- strxfrm.c.orig 2003-05-20 15:23:55.000000000 -0700
2 +++ strxfrm.c 2005-04-02 17:59:53.000000000 -0800
5 __FBSDID("$FreeBSD: src/lib/libc/string/strxfrm.c,v 1.15 2002/09/06 11:24:06 tjr Exp $");
7 +#include "xlocale_private.h"
16 + * In the non-POSIX case, we transform each character into a string of
17 + * characters representing the character's priority. Since char is usually
18 + * signed, we are limited by 7 bits per byte. To avoid zero, we need to add
19 + * XFRM_OFFSET, so we can't use a full 7 bits. For simplicity, we choose 6
20 + * bits per byte. We choose 4 bytes per character as a good compromise
21 + * between maximum coverage and minimum size. This gives 24 bits, or 16M
22 + * priorities. So we choose COLLATE_MAX_PRIORITY to be (2^24 - 1). This
23 + * this can be increased if more is needed.
27 +#define XFRM_OFFSET ('0') /* make all printable characters */
29 +#define XFRM_MASK ((1 << XFRM_SHIFT) - 1)
32 +xfrm(unsigned char *p, int pri)
35 + p[3] = (pri & XFRM_MASK) + XFRM_OFFSET;
37 + p[2] = (pri & XFRM_MASK) + XFRM_OFFSET;
39 + p[1] = (pri & XFRM_MASK) + XFRM_OFFSET;
41 + p[0] = (pri & XFRM_MASK) + XFRM_OFFSET;
45 -strxfrm(char * __restrict dest, const char * __restrict src, size_t len)
46 +strxfrm_l(char * __restrict dest, const char * __restrict src, size_t len,
52 + wchar_t *wcs, *xf[2];
56 + if (!*src && dest) {
62 - if (__collate_load_error) {
63 + NORMALIZE_LOCALE(loc);
64 + if (loc->__collate_load_error || (wcs = __collate_mbstowcs(src, loc)) == NULL) {
74 - ss = s = __collate_substitute(src);
76 - while (*s && !prim) {
77 - __collate_lookup(s, &l, &prim, &sec);
79 + __collate_xfrm(wcs, xf, loc);
81 + slen = wcslen(xf[0]) * XFRM_BYTES;
83 + slen += (wcslen(xf[1]) + 1) * XFRM_BYTES;
87 + unsigned char buf[XFRM_BYTES];
93 + xfrm(bp = buf, *w++);
96 + *dest++ = *(char *)bp++;
102 - *dest++ = (char)prim;
103 + if ((w = xf[1]) != NULL) {
109 + *dest++ = *(char *)bp++;
118 + xfrm(bp = buf, *w++);
121 + *dest++ = *(char *)bp++;
144 +strxfrm(char * __restrict dest, const char * __restrict src, size_t len)
146 + return strxfrm_l(dest, src, len, __current_locale());