int i;
int i, resultLen = 0;  result.Truncate();
convert_native_to_ucs2(const char *input, unsigned inputLen, PRUnichar **result){#ifdef HAVE_MBRTOWC    mbstate_t ps = {0};#endif    PRUnichar *p;    int i;    // allocate space for largest possible result    p = *result = (PRUnichar *) nsMemory::Alloc((inputLen + 1) * sizeof(PRUnichar));    if (!p) {        NS_ERROR("memory allocation failed");        return -1;    }    // cannot use wchar_t here since it may have been redefined (e.g.,    // via -fshort-wchar).  hopefully, sizeof(tmp) is sufficient XP.    unsigned int tmp = 0;    while (*input) {#ifdef HAVE_MBRTOWC        i = (int) mbrtowc((wchar_t *) &tmp, input, inputLen, &ps);#else        // XXX is this thread-safe?        i = (int) mbtowc((wchar_t *) &tmp, input, inputLen);#endif        if (i < 0) {            NS_WARNING("mbtowc failed: possible charset mismatch");#ifdef TOLERATE_UCONV_FAILURE            tmp = (unsigned char) *input;            i = 1;#else            nsMemory::Free(*result);            *result = nsnull;            return -1;#endif        }        *p = (PRUnichar) tmp;        input += i;        inputLen -= i;        p++;    }    *p = '\0';    return p - *result;}