wrote = PR_snprintf(p2, available, "%s%s;q=0.%02u", comma, token, (unsigned) (q * 100.0));
wrote = PR_snprintf(p2, available, "%s%s;q=0.%01u", comma, token, QVAL_TO_UINT(q));
PrepareAcceptLanguages(const char *i_AcceptLanguages, nsACString &o_AcceptLanguages){    if (!i_AcceptLanguages)        return NS_OK;    PRUint32 n, size, wrote;    double q, dec;    char *p, *p2, *token, *q_Accept, *o_Accept;    const char *comma;    PRInt32 available;    o_Accept = nsCRT::strdup(i_AcceptLanguages);    if (nsnull == o_Accept)        return NS_ERROR_OUT_OF_MEMORY;    for (p = o_Accept, n = size = 0; '\0' != *p; p++) {        if (*p == ',') n++;            size++;    }    available = size + ++n * 11 + 1;    q_Accept = new char[available];    if ((char *) 0 == q_Accept)        return nsnull;    *q_Accept = '\0';    q = 1.0;    dec = q / (double) n;    n = 0;    p2 = q_Accept;    for (token = nsCRT::strtok(o_Accept, ",", &p);         token != (char *) 0;         token = nsCRT::strtok(p, ",", &p))    {        while (*token == ' ' || *token == '\x9') token++;        char* trim;        trim = PL_strpbrk(token, "; \x9");        if (trim != (char*)0)  // remove "; q=..." if present            *trim = '\0';        if (*token != '\0') {            comma = n++ != 0 ? ", " : ""; // delimiter if not first item            if (q < 0.9995)                wrote = PR_snprintf(p2, available, "%s%s;q=0.%02u", comma, token, (unsigned) (q * 100.0));            else                wrote = PR_snprintf(p2, available, "%s%s", comma, token);            q -= dec;            p2 += wrote;            available -= wrote;            NS_ASSERTION(available > 0, "allocated string not long enough");        }    }    nsCRT::free(o_Accept);    o_AcceptLanguages.Assign((const char *) q_Accept);    delete [] q_Accept;    return NS_OK;}