2 Unix SMB/CIFS implementation.
3 Character set conversion Extensions
4 Copyright (C) Igor Vergeichik <iverg@mail.ru> 2001
5 Copyright (C) Andrew Tridgell 2001
6 Copyright (C) Simo Sorce 2001
7 Copyright (C) Martin Pool 2003
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #endif /* HAVE_CONFIG_H */
32 #include <sys/param.h>
35 #include <atalk/logger.h>
38 #include <netatalk/endian.h>
39 #include <atalk/unicode.h>
41 #ifdef HAVE_USABLE_ICONV
57 * @brief Character-set conversion routines built on our iconv.
59 * @note Samba's internal character set (at least in the 3.0 series)
60 * is always the same as the one for the Unix filesystem. It is
61 * <b>not</b> necessarily UTF-8 and may be different on machines that
62 * need i18n filenames to be compatible with Unix software. It does
63 * have to be a superset of ASCII. All multibyte sequences must start
64 * with a byte with the high bit set.
70 #define MAX_CHARSETS 10
72 #define CHECK_FLAGS(a,b) (((a)!=NULL) ? (*(a) & (b)) : 0 )
74 static atalk_iconv_t conv_handles[MAX_CHARSETS][MAX_CHARSETS];
75 static char* charset_names[MAX_CHARSETS];
76 static struct charset_functions* charsets[MAX_CHARSETS];
77 static char hexdig[] = "0123456789abcdef";
78 #define hextoint( c ) ( isdigit( c ) ? c - '0' : c + 10 - 'a' )
81 * Return the name of a charset to give to iconv().
83 static const char *charset_name(charset_t ch)
85 const char *ret = NULL;
87 if (ch == CH_UCS2) ret = "UCS-2LE";
88 else if (ch == CH_UNIX) ret = "LOCALE"; /*lp_unix_charset();*/
89 else if (ch == CH_MAC) ret = "MAC_ROMAN"; /*lp_display_charset();*/
90 else if (ch == CH_UTF8) ret = "UTF8";
91 else if (ch == CH_UTF8_MAC) ret = "UTF8-MAC";
94 ret = charset_names[ch];
96 #if defined(HAVE_NL_LANGINFO) && defined(CODESET)
97 if (ret && strcasecmp(ret, "LOCALE") == 0) {
98 const char *ln = NULL;
100 #ifdef HAVE_SETLOCALE
101 setlocale(LC_ALL, "");
103 ln = nl_langinfo(CODESET);
105 /* Check whether the charset name is supported
107 atalk_iconv_t handle = atalk_iconv_open(ln,"UCS-2LE");
108 if (handle == (atalk_iconv_t) -1) {
109 LOG(log_debug, logtype_default, "Locale charset '%s' unsupported, using ASCII instead", ln);
112 atalk_iconv_close(handle);
119 if (!ret || !*ret) ret = "ASCII";
123 struct charset_functions* get_charset_functions (charset_t ch)
125 if (charsets[ch] != NULL)
128 charsets[ch] = find_charset_functions(charset_name(ch));
134 void lazy_initialize_conv(void)
136 static int initialized = 0;
144 charset_t add_charset(char* name)
146 static charset_t max_charset_t = NUM_CHARSETS-1;
147 charset_t cur_charset_t = max_charset_t+1;
150 lazy_initialize_conv();
152 for (c1=0; c1<=max_charset_t;c1++) {
153 if ( strcasecmp(name, charset_name(c1)) == 0)
157 if ( cur_charset_t >= MAX_CHARSETS ) {
158 LOG (log_debug, logtype_default, "Adding charset %s failed, too many charsets (max. %u allowed)",
160 return (charset_t) -1;
163 /* First try to setup the required conversions */
165 conv_handles[cur_charset_t][CH_UCS2] = atalk_iconv_open( charset_name(CH_UCS2), name);
166 if (conv_handles[cur_charset_t][CH_UCS2] == (atalk_iconv_t)-1) {
167 LOG(log_error, logtype_default, "Required conversion from %s to %s not supported",
168 name, charset_name(CH_UCS2));
169 conv_handles[cur_charset_t][CH_UCS2] = NULL;
170 return (charset_t) -1;
173 conv_handles[CH_UCS2][cur_charset_t] = atalk_iconv_open( name, charset_name(CH_UCS2));
174 if (conv_handles[CH_UCS2][cur_charset_t] == (atalk_iconv_t)-1) {
175 LOG(log_error, logtype_default, "Required conversion from %s to %s not supported",
176 charset_name(CH_UCS2), name);
177 conv_handles[CH_UCS2][cur_charset_t] = NULL;
178 return (charset_t) -1;
181 /* register the new charset_t name */
182 charset_names[cur_charset_t] = strdup(name);
184 charsets[cur_charset_t] = get_charset_functions (cur_charset_t);
188 LOG(log_debug, logtype_default, "Added charset %s with handle %u", name, cur_charset_t);
190 return (cur_charset_t);
194 * Initialize iconv conversion descriptors.
196 * This is called the first time it is needed, and also called again
197 * every time the configuration is reloaded, because the charset or
198 * codepage might have changed.
200 void init_iconv(void)
204 /* so that charset_name() works we need to get the UNIX<->UCS2 going
206 if (!conv_handles[CH_UNIX][CH_UCS2])
207 conv_handles[CH_UNIX][CH_UCS2] = atalk_iconv_open("UCS-2LE", "ASCII");
209 if (!conv_handles[CH_UCS2][CH_UNIX])
210 conv_handles[CH_UCS2][CH_UNIX] = atalk_iconv_open("ASCII", "UCS-2LE");
212 for (c1=0;c1<NUM_CHARSETS;c1++) {
213 const char *name = charset_name((charset_t)c1);
215 conv_handles[c1][CH_UCS2] = atalk_iconv_open( charset_name(CH_UCS2), name);
216 if (conv_handles[c1][CH_UCS2] == (atalk_iconv_t)-1) {
217 LOG(log_error, logtype_default, "Required conversion from %s to %s not supported",
218 name, charset_name(CH_UCS2));
219 conv_handles[c1][CH_UCS2] = NULL;
222 conv_handles[CH_UCS2][c1] = atalk_iconv_open( name, charset_name(CH_UCS2));
223 if (conv_handles[CH_UCS2][1] == (atalk_iconv_t)-1) {
224 LOG(log_error, logtype_default, "Required conversion from %s to %s not supported",
225 charset_name(CH_UCS2), name);
226 conv_handles[c1][c1] = NULL;
229 charsets[c1] = get_charset_functions (c1);
234 * Convert string from one encoding to another, making error checking etc
236 * @param src pointer to source string (multibyte or singlebyte)
237 * @param srclen length of the source string in bytes
238 * @param dest pointer to destination string (multibyte or singlebyte)
239 * @param destlen maximal length allowed for string
240 * @returns the number of bytes occupied in the destination
242 static size_t convert_string_internal(charset_t from, charset_t to,
243 void const *src, size_t srclen,
244 void *dest, size_t destlen)
248 const char* inbuf = (const char*)src;
249 char* outbuf = (char*)dest;
250 atalk_iconv_t descriptor;
252 if (srclen == (size_t)-1)
253 srclen = strlen(src)+1;
255 lazy_initialize_conv();
257 descriptor = conv_handles[from][to];
259 if (descriptor == (atalk_iconv_t)-1 || descriptor == (atalk_iconv_t)0) {
265 retval = atalk_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len);
266 if(retval==(size_t)-1) {
267 const char *reason="unknown error";
270 reason="Incomplete multibyte sequence";
273 reason="No more room";
276 reason="Illegal multibyte sequence";
279 LOG(log_debug, logtype_default,"Conversion error: %s(%s)\n",reason,inbuf);
283 /* Terminate the string */
284 if (to == CH_UCS2 && destlen-o_len >= 2) {
288 else if ( destlen-o_len > 0)
291 return destlen-o_len;
295 size_t convert_string(charset_t from, charset_t to,
296 void const *src, size_t srclen,
297 void *dest, size_t destlen)
301 char buffer[MAXPATHLEN];
302 char buffer2[MAXPATHLEN];
305 lazy_initialize_conv();
307 /* convert from_set to UCS2 */
308 if ((size_t)(-1) == ( o_len = convert_string_internal( from, CH_UCS2, src, srclen, buffer, MAXPATHLEN)) ) {
309 LOG(log_error, logtype_default, "Conversion failed ( %s to CH_UCS2 )", charset_name(from));
313 /* Do pre/decomposition */
314 if ( ((!(charsets[to]) || !(charsets[to]->flags & CHARSET_DECOMPOSED)) &&
315 (!(charsets[from]) || (charsets[from]->flags & CHARSET_DECOMPOSED))))
317 if ((charsets[to] && charsets[to]->flags & CHARSET_DECOMPOSED) )
323 switch (composition) {
329 if ( (size_t)-1 == (i_len = precompose_w((ucs2_t *)buffer, o_len, (ucs2_t *)u, &i_len)) )
333 if ( (size_t)-1 == (i_len = decompose_w((ucs2_t *)buffer, o_len, (ucs2_t *)u, &i_len)) )
338 /* Convert UCS2 to to_set */
339 if ((size_t)(-1) == ( o_len = convert_string_internal( CH_UCS2, to, u, i_len, dest, destlen)) ) {
340 LOG(log_error, logtype_default, "Conversion failed (CH_UCS2 to %s):%s", charset_name(to), strerror(errno));
350 * Convert between character sets, allocating a new buffer for the result.
352 * @param srclen length of source buffer.
353 * @param dest always set at least to NULL
354 * @note -1 is not accepted for srclen.
356 * @returns Size in bytes of the converted string; or -1 in case of error.
359 static size_t convert_string_allocate_internal(charset_t from, charset_t to,
360 void const *src, size_t srclen, char **dest)
362 size_t i_len, o_len, destlen;
364 const char *inbuf = (const char *)src;
366 atalk_iconv_t descriptor;
370 if (src == NULL || srclen == (size_t)-1)
373 lazy_initialize_conv();
375 descriptor = conv_handles[from][to];
377 if (descriptor == (atalk_iconv_t)-1 || descriptor == (atalk_iconv_t)0) {
378 /* conversion not supported, return -1*/
379 LOG(log_debug, logtype_default, "convert_string_allocate: conversion not supported!\n");
383 destlen = MAX(srclen, 512);
386 destlen = destlen * 2;
387 ob = (char *)realloc(outbuf, destlen);
389 LOG(log_debug, logtype_default,"convert_string_allocate: realloc failed!\n");
397 retval = atalk_iconv(descriptor,
400 if(retval == (size_t)-1) {
401 const char *reason="unknown error";
404 reason="Incomplete multibyte sequence";
409 reason="Illegal multibyte sequence";
412 LOG(log_debug, logtype_default,"Conversion error: %s(%s)\n",reason,inbuf);
413 /* smb_panic(reason); */
418 destlen = destlen - o_len;
420 /* Terminate the string */
421 if (to == CH_UCS2 && destlen-o_len >= 2) {
424 *dest = (char *)realloc(ob,destlen+2);
426 else if ( destlen-o_len > 0) {
428 *dest = (char *)realloc(ob,destlen+1);
431 if (destlen && !*dest) {
432 LOG(log_debug, logtype_default, "convert_string_allocate: out of memory!\n");
441 size_t convert_string_allocate(charset_t from, charset_t to,
442 void const *src, size_t srclen,
447 char buffer[MAXPATHLEN];
448 char buffer2[MAXPATHLEN];
451 lazy_initialize_conv();
453 /* convert from_set to UCS2 */
454 if ((size_t)(-1) == ( o_len = convert_string_internal( from, CH_UCS2, src, srclen, buffer, MAXPATHLEN)) ) {
455 LOG(log_error, logtype_default, "Conversion failed ( %s to CH_UCS2 )", charset_name(from));
459 /* Do pre/decomposition */
460 if ( ((!(charsets[to]) || !(charsets[to]->flags & CHARSET_DECOMPOSED)) &&
461 (!(charsets[from]) || (charsets[from]->flags & CHARSET_DECOMPOSED))))
463 if ((charsets[to] && charsets[to]->flags & CHARSET_DECOMPOSED) )
469 switch (composition) {
475 if ( (size_t)-1 == (i_len = precompose_w((ucs2_t *)buffer, o_len, (ucs2_t *)u, &i_len)) )
479 if ( (size_t)-1 == (i_len = decompose_w((ucs2_t *)buffer, o_len, (ucs2_t *)u, &i_len)) )
484 /* Convert UCS2 to to_set */
485 if ((size_t)(-1) == ( o_len = convert_string_allocate_internal( CH_UCS2, to, u, i_len, dest)) )
486 LOG(log_error, logtype_default, "Conversion failed (CH_UCS2 to %s):%s", charset_name(to), strerror(errno));
492 size_t charset_strupper(charset_t ch, const char *src, size_t srclen, char *dest, size_t destlen)
497 size = convert_string_allocate_internal(ch, CH_UCS2, src, srclen,
499 if (size == (size_t)-1) {
503 if (!strupper_w((ucs2_t *)buffer) && (dest == src)) {
508 size = convert_string_internal(CH_UCS2, ch, buffer, size, dest, destlen);
513 size_t charset_strlower(charset_t ch, const char *src, size_t srclen, char *dest, size_t destlen)
518 size = convert_string_allocate_internal(ch, CH_UCS2, src, srclen,
520 if (size == (size_t)-1) {
524 if (!strlower_w((ucs2_t *)buffer) && (dest == src)) {
529 size = convert_string_internal(CH_UCS2, ch, buffer, size, dest, destlen);
535 size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
537 return charset_strupper( CH_UNIX, src, srclen, dest, destlen);
540 size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
542 return charset_strlower( CH_UNIX, src, srclen, dest, destlen);
545 size_t utf8_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
547 return charset_strupper( CH_UTF8, src, srclen, dest, destlen);
550 size_t utf8_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
552 return charset_strlower( CH_UTF8, src, srclen, dest, destlen);
556 * Copy a string from a charset_t char* src to a UCS2 destination, allocating a buffer
558 * @param dest always set at least to NULL
560 * @returns The number of bytes occupied by the string in the destination
561 * or -1 in case of error.
564 size_t charset_to_ucs2_allocate(charset_t ch, ucs2_t **dest, const char *src)
566 size_t src_len = strlen(src)+1;
569 return convert_string_allocate(ch, CH_UCS2, src, src_len, (char**) dest);
573 * Copy a string from a charset_t char* src to a UTF-8 destination, allocating a buffer
575 * @param dest always set at least to NULL
577 * @returns The number of bytes occupied by the string in the destination
580 size_t charset_to_utf8_allocate(charset_t ch, char **dest, const char *src)
582 size_t src_len = strlen(src)+1;
585 return convert_string_allocate(ch, CH_UTF8, src, src_len, dest);
589 * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer
591 * @param dest always set at least to NULL
593 * @returns The number of bytes occupied by the string in the destination
596 size_t ucs2_to_charset_allocate(charset_t ch, char **dest, const ucs2_t *src)
598 size_t src_len = (strlen_w(src)+1) * sizeof(ucs2_t);
600 return convert_string_allocate(CH_UCS2, ch, src, src_len, dest);
604 * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer
606 * @param dest always set at least to NULL
608 * @returns The number of bytes occupied by the string in the destination
611 size_t utf8_to_charset_allocate(charset_t ch, char **dest, const char *src)
613 size_t src_len = strlen(src)+1;
615 return convert_string_allocate(CH_UTF8, ch, src, src_len, dest);
618 size_t charset_precompose ( charset_t ch, char * src, size_t inlen, char * dst, size_t outlen)
625 if ((size_t)(-1) == (len = convert_string_allocate_internal(ch, CH_UCS2, src, inlen, &buffer)) )
630 if ( (size_t)-1 == (ilen = precompose_w((ucs2_t *)buffer, len, (ucs2_t *)u, &ilen)) ) {
635 if ((size_t)(-1) == (len = convert_string_internal( CH_UCS2, ch, u, ilen, dst, outlen)) ) {
645 size_t charset_decompose ( charset_t ch, char * src, size_t inlen, char * dst, size_t outlen)
652 if ((size_t)(-1) == (len = convert_string_allocate_internal(ch, CH_UCS2, src, inlen, &buffer)) )
657 if ( (size_t)-1 == (ilen = decompose_w((ucs2_t *)buffer, len, (ucs2_t *)u, &ilen)) ) {
662 if ((size_t)(-1) == (len = convert_string_internal( CH_UCS2, ch, u, ilen, dst, outlen)) ) {
672 size_t utf8_precompose ( char * src, size_t inlen, char * dst, size_t outlen)
674 return charset_precompose ( CH_UTF8, src, inlen, dst, outlen);
677 size_t utf8_decompose ( char * src, size_t inlen, char * dst, size_t outlen)
679 return charset_decompose ( CH_UTF8, src, inlen, dst, outlen);
682 static char debugbuf[ MAXPATHLEN +1 ];
683 char * debug_out ( char * seq, size_t len)
689 p = (unsigned char*) seq;
692 for ( i = 0; i<=(len-1); i++)
694 sprintf(q, "%2.2x.", *p);
704 * Convert from MB to UCS2 charset
706 * CONV_UNESCAPEHEX: ':XXXX' will be converted to an UCS2 character
707 * CONV_IGNORE: unconvertable characters will be replaced with '_'
709 * This will *not* work if the destination charset is not multibyte, i.e. UCS2->UCS2 will fail
710 * The (un)escape scheme is not compatible to the old cap style escape. This is bad, we need it
711 * for e.g. HFS cdroms.
714 static size_t pull_charset_flags (charset_t from_set, charset_t cap_charset, char* src, size_t srclen, char* dest, size_t destlen, u_int16_t *flags)
716 size_t i_len, o_len, hlen;
717 size_t retval, j = 0;
718 const char* inbuf = (const char*)src;
719 char* outbuf = (char*)dest;
720 atalk_iconv_t descriptor;
721 atalk_iconv_t descriptor_cap;
726 if (srclen == (size_t)-1)
727 srclen = strlen(src)+1;
729 lazy_initialize_conv();
731 descriptor = conv_handles[from_set][CH_UCS2];
732 descriptor_cap = conv_handles[cap_charset][CH_UCS2];
734 if (descriptor == (atalk_iconv_t)-1 || descriptor == (atalk_iconv_t)0) {
743 if ( flags && (*flags & CONV_UNESCAPEHEX)) {
744 if ( NULL != (s = strchr ( inbuf, ':'))) {
745 j = i_len - (s - inbuf);
746 if ( 0 == (i_len = (s - inbuf)))
751 retval = atalk_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len);
752 if(retval==(size_t)-1) {
753 if (errno == EILSEQ && flags && (*flags & CONV_IGNORE)) {
754 *flags |= CONV_REQMANGLE;
755 return destlen-o_len;
762 if (j && flags && (*flags & CONV_UNESCAPEHEX )) {
763 /* we're at the start on an hex encoded ucs2 char */
769 isxdigit( *(inbuf+1)) && isxdigit( *(inbuf+2)) ) {
771 while ( *inbuf == ':' && j >=3 &&
772 isxdigit( *(inbuf+1)) && isxdigit( *(inbuf+2)) ) {
774 h[hlen] = hextoint( *inbuf ) << 4;
776 h[hlen++] |= hextoint( *inbuf );
780 h_buf = (const char*) h;
781 if ((size_t) -1 == (retval = atalk_iconv(descriptor_cap, &h_buf, &hlen, &outbuf, &o_len)) ) {
782 if (errno == EILSEQ && CHECK_FLAGS(flags, CONV_IGNORE)) {
783 *flags |= CONV_REQMANGLE;
784 return destlen-o_len;
792 /* We have an invalid :xx sequence */
793 if (CHECK_FLAGS(flags, CONV_IGNORE)) {
794 *flags |= CONV_REQMANGLE;
795 return destlen-o_len;
805 goto conversion_loop;
810 return destlen-o_len;
814 * Convert from UCS2 to MB charset
816 * CONV_ESCAPEDOTS: escape leading dots
817 * CONV_ESCAPEHEX: unconvertable characters and '/' will be escaped to :XXXX
818 * CONV_IGNORE: unconvertable characters will be replaced with '_'
820 * CONV_IGNORE and CONV_ESCAPEHEX can't work together. Should we check this ?
821 * This will *not* work if the destination charset is not multibyte, i.e. UCS2->UCS2 will fail
822 * The escape scheme is not compatible to the old cap style escape. This is bad, we need it
823 * for e.g. HFS cdroms.
827 static size_t push_charset_flags (charset_t to_set, charset_t cap_set, char* src, size_t srclen, char* dest, size_t destlen, u_int16_t *flags)
829 size_t i_len, o_len, i;
830 size_t retval, j = 0;
831 const char* inbuf = (const char*)src;
832 char* outbuf = (char*)dest;
833 atalk_iconv_t descriptor;
835 char *buf, *buf_save;
838 lazy_initialize_conv();
840 descriptor = conv_handles[CH_UCS2][to_set];
842 if (descriptor == (atalk_iconv_t)-1 || descriptor == (atalk_iconv_t)0) {
850 if (inbuf[0] == '.' && inbuf[1] == 0 && flags && (*flags & CONV_ESCAPEDOTS)) {
862 if (flags) *flags |= CONV_REQESCAPE;
866 if ( flags && (*flags & CONV_ESCAPEHEX)) {
867 for ( i = 0; i < i_len; i+=2) {
868 if ( inbuf[i] == '/' && inbuf[i+1] == 0) {
870 if ( 0 == ( i_len = i))
873 } else if ( inbuf[i] == ':' && inbuf[i+1] == 0) {
880 retval = atalk_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len);
881 if (retval==(size_t)-1) {
882 if (errno == EILSEQ && CHECK_FLAGS(flags, CONV_IGNORE)) {
883 *flags |= CONV_REQMANGLE;
884 return destlen -o_len;
886 else if ( errno == EILSEQ && flags && (*flags & CONV_ESCAPEHEX)) {
891 if ((size_t) -1 == (buflen = convert_string_allocate_internal(CH_UCS2, cap_set, inbuf, 2, &buf)) )
900 *outbuf++ = hexdig[ ( *buf & 0xf0 ) >> 4 ];
901 *outbuf++ = hexdig[ *buf & 0x0f ];
910 if (flags) *flags |= CONV_REQESCAPE;
912 goto conversion_loop;
919 if (j && flags && (*flags & CONV_ESCAPEHEX)) {
924 o_save[destlen -o_len] = ':';
925 o_save[destlen -o_len+1] = '2';
926 o_save[destlen -o_len+2] = 'f';
933 goto conversion_loop;
935 return destlen -o_len;
938 size_t convert_charset ( charset_t from_set, charset_t to_set, charset_t cap_charset, char* src, size_t src_len, char* dest, size_t dest_len, u_int16_t *flags)
942 char buffer[MAXPATHLEN];
943 char buffer2[MAXPATHLEN];
946 lazy_initialize_conv();
948 /* convert from_set to UCS2 */
949 if ((size_t)(-1) == ( o_len = pull_charset_flags( from_set, cap_charset, src, src_len, buffer, MAXPATHLEN, flags)) ) {
950 LOG(log_error, logtype_default, "Conversion failed ( %s to CH_UCS2 )", charset_name(from_set));
957 /* Do pre/decomposition */
958 if (CHECK_FLAGS(flags, CONV_PRECOMPOSE) ||
959 ((!(charsets[to_set]) || !(charsets[to_set]->flags & CHARSET_DECOMPOSED)) &&
960 (!(charsets[from_set]) || (charsets[from_set]->flags & CHARSET_DECOMPOSED))))
962 if (CHECK_FLAGS(flags, CONV_DECOMPOSE) || (charsets[to_set] && charsets[to_set]->flags & CHARSET_DECOMPOSED) )
968 switch (composition) {
974 if ( (size_t)-1 == (i_len = precompose_w((ucs2_t *)buffer, o_len, (ucs2_t *)u, &i_len)) )
978 if ( (size_t)-1 == (i_len = decompose_w((ucs2_t *)buffer, o_len, (ucs2_t *)u, &i_len)) )
983 /* Do case conversions */
984 if (CHECK_FLAGS(flags, CONV_TOUPPER)) {
985 if (!strupper_w((ucs2_t *) u))
988 if (CHECK_FLAGS(flags, CONV_TOLOWER)) {
989 if (!strlower_w((ucs2_t *) u))
993 /* Convert UCS2 to to_set */
994 if ((size_t)(-1) == ( o_len = push_charset_flags( to_set, cap_charset, u, i_len, dest, dest_len, flags )) ) {
995 LOG(log_error, logtype_default,
996 "Conversion failed (CH_UCS2 to %s):%s", charset_name(to_set), strerror(errno));