/* Take a block of ASCII chars in and try to convert it to an UTF-8 block of chars out. Returns 0 if success, or -1 otherwise The value of @inlen after return is the number of octets consumed if the return value is positive, else unpredictable. The value of @outlen after return is the number of octets consumed.  */
static int asciiToUTF8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
/* Take a block of ASCII chars in and try to convert it to an UTF-8 block of chars out. Returns 0 if success, or -1 otherwise The value of @inlen after return is the number of octets consumed if the return value is positive, else unpredictable. The value of @outlen after return is the number of octets consumed.  */
static int asciiToUTF8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
{
    unsigned char* outstart = out;
    const unsigned char* base = in;
    const unsigned char* processed = in;
    unsigned char* outend = out + *outlen;
    const unsigned char* inend;
    unsigned int c;
    inend = in + (*inlen);
    while ((in < inend) && (out - outstart + 5 < *outlen)) {
	c= *in++;
        if (out >= outend)
	    break;
        if (c < 0x80) {
	    *out++ = c;
	} else {
	    *outlen = out - outstart;
	    *inlen = processed - base;
	    return(-1);
	}
	processed = (const unsigned char*) in;
    }
    *outlen = out - outstart;
    *inlen = processed - base;
    return(*outlen);
}