/* Returns the number of bytes written, or -1 if lack of space. The value of *inlen after return is the number of octets consumed if the return value is positive, else unpredictable.  */
static int UTF8ToUTF8(unsigned char *out, int *outlen, const unsigned char *inb, int *inlenb)
/* Returns the number of bytes written, or -1 if lack of space. The value of *inlen after return is the number of octets consumed if the return value is positive, else unpredictable.  */
static int UTF8ToUTF8(unsigned char *out, int *outlen, const unsigned char *inb, int *inlenb)
{
    int len;
    if ((out == NULL) || (inb == NULL) || (outlen == NULL) || (inlenb == NULL))
	return(-1);
    if (*outlen > *inlenb) {
	len = *inlenb;
    } else {
	len = *outlen;
    }
    if (len < 0)
	return(-1);
    memcpy(out, inb, len);
    *outlen = len;
    *inlenb = len;
    return(*outlen);
}