/*
* "$Id$"
*
- * Transcoding support for CUPS.
+ * Transcoding support for CUPS.
*
- * Copyright 2007-2010 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products.
*
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
- * This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- * _cupsCharmapFlush() - Flush all character set maps out of cache.
- * cupsCharsetToUTF8() - Convert legacy character set to UTF-8.
- * cupsUTF8ToCharset() - Convert UTF-8 to legacy character set.
- * cupsUTF8ToUTF32() - Convert UTF-8 to UTF-32.
- * cupsUTF32ToUTF8() - Convert UTF-32 to UTF-8.
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
* Check for valid arguments...
*/
- DEBUG_printf(("2cupsCharsetToUTF8(dest=%p, src=\"%s\", maxout=%d, encoding=%d)",
- dest, src, maxout, encoding));
+ DEBUG_printf(("2cupsCharsetToUTF8(dest=%p, src=\"%s\", maxout=%d, encoding=%d)", (void *)dest, src, maxout, encoding));
if (!dest || !src || maxout < 1)
{
if (encoding == CUPS_UTF8 || encoding <= CUPS_US_ASCII ||
encoding >= CUPS_ENCODING_VBCS_END)
{
- strlcpy((char *)dest, src, maxout);
+ strlcpy((char *)dest, src, (size_t)maxout);
return ((int)strlen((char *)dest));
}
if (ch & 128)
{
- *destptr++ = 0xc0 | (ch >> 6);
- *destptr++ = 0x80 | (ch & 0x3f);
+ *destptr++ = (cups_utf8_t)(0xc0 | (ch >> 6));
+ *destptr++ = (cups_utf8_t)(0x80 | (ch & 0x3f));
}
else
- *destptr++ = ch;
+ *destptr++ = (cups_utf8_t)ch;
}
*destptr = '\0';
if (map_encoding != encoding)
{
+ char toset[1024]; /* Destination character set */
+
_cupsCharmapFlush();
+ snprintf(toset, sizeof(toset), "%s//IGNORE", _cupsEncodingName(encoding));
+
+ map_encoding = encoding;
map_from_utf8 = iconv_open(_cupsEncodingName(encoding), "UTF-8");
- map_to_utf8 = iconv_open("UTF-8", _cupsEncodingName(encoding));
- map_encoding = encoding;
+ map_to_utf8 = iconv_open("UTF-8", toset);
}
if (map_to_utf8 != (iconv_t)-1)
char *altdestptr = (char *)dest; /* Silence bogus GCC type-punned */
srclen = strlen(src);
- outBytesLeft = maxout - 1;
+ outBytesLeft = (size_t)maxout - 1;
iconv(map_to_utf8, (char **)&src, &srclen, &altdestptr, &outBytesLeft);
*altdestptr = '\0';
if (encoding == CUPS_UTF8 ||
encoding >= CUPS_ENCODING_VBCS_END)
{
- strlcpy(dest, (char *)src, maxout);
+ strlcpy(dest, (char *)src, (size_t)maxout);
return ((int)strlen(dest));
}
ch = ((ch & 0x1f) << 6) | (*src++ & 0x3f);
if (ch < maxch)
- *destptr++ = ch;
+ *destptr++ = (char)ch;
else
*destptr++ = '?';
}
(ch & 0xf8) == 0xf0)
*destptr++ = '?';
else if (!(ch & 0x80))
- *destptr++ = ch;
+ *destptr++ = (char)ch;
}
*destptr = '\0';
if (map_encoding != encoding)
{
+ char toset[1024]; /* Destination character set */
+
_cupsCharmapFlush();
- map_from_utf8 = iconv_open(_cupsEncodingName(encoding), "UTF-8");
- map_to_utf8 = iconv_open("UTF-8", _cupsEncodingName(encoding));
+ snprintf(toset, sizeof(toset), "%s//IGNORE", _cupsEncodingName(encoding));
+
map_encoding = encoding;
+ map_from_utf8 = iconv_open(_cupsEncodingName(encoding), "UTF-8");
+ map_to_utf8 = iconv_open("UTF-8", toset);
}
if (map_from_utf8 != (iconv_t)-1)
char *altsrc = (char *)src; /* Silence bogus GCC type-punned */
srclen = strlen((char *)src);
- outBytesLeft = maxout - 1;
+ outBytesLeft = (size_t)maxout - 1;
iconv(map_from_utf8, &altsrc, &srclen, &destptr, &outBytesLeft);
*destptr = '\0';
* Check for valid arguments and clear output...
*/
- DEBUG_printf(("2cupsUTF8ToUTF32(dest=%p, src=\"%s\", maxout=%d)", dest,
- src, maxout));
+ DEBUG_printf(("2cupsUTF8ToUTF32(dest=%p, src=\"%s\", maxout=%d)", (void *)dest, src, maxout));
if (dest)
*dest = 0;
return (-1);
}
- ch32 = ((ch & 0x1f) << 6) | (next & 0x3f);
+ ch32 = (cups_utf32_t)((ch & 0x1f) << 6) | (cups_utf32_t)(next & 0x3f);
/*
* Check for non-shortest form (invalid UTF-8)...
return (-1);
}
- ch32 = ((ch & 0x0f) << 6) | (next & 0x3f);
+ ch32 = (cups_utf32_t)((ch & 0x0f) << 6) | (cups_utf32_t)(next & 0x3f);
next = *src++;
if ((next & 0xc0) != 0x80)
return (-1);
}
- ch32 = (ch32 << 6) | (next & 0x3f);
+ ch32 = (ch32 << 6) | (cups_utf32_t)(next & 0x3f);
/*
* Check for non-shortest form (invalid UTF-8)...
return (-1);
}
- ch32 = ((ch & 0x07) << 6) | (next & 0x3f);
+ ch32 = (cups_utf32_t)((ch & 0x07) << 6) | (cups_utf32_t)(next & 0x3f);
next = *src++;
if ((next & 0xc0) != 0x80)
return (-1);
}
- ch32 = (ch32 << 6) | (next & 0x3f);
+ ch32 = (ch32 << 6) | (cups_utf32_t)(next & 0x3f);
next = *src++;
if ((next & 0xc0) != 0x80)
return (-1);
}
- ch32 = (ch32 << 6) | (next & 0x3f);
+ ch32 = (ch32 << 6) | (cups_utf32_t)(next & 0x3f);
/*
* Check for non-shortest form (invalid UTF-8)...
* Check for valid arguments and clear output...
*/
- DEBUG_printf(("2cupsUTF32ToUTF8(dest=%p, src=%p, maxout=%d)", dest, src,
- maxout));
+ DEBUG_printf(("2cupsUTF32ToUTF8(dest=%p, src=%p, maxout=%d)", (void *)dest, (void *)src, maxout));
if (dest)
*dest = '\0';