PRUint32 rawSegmentLen = nsCRT::strlen(fromRawSegment);
PRUint32 rawSegmentLen = strlen(fromRawSegment);
AHTC_WriteFunc(nsIInputStream * in,               void *closure,               const char *fromRawSegment,               PRUint32 toOffset, PRUint32 count, PRUint32 * writeCount){    if (nsnull == writeCount || nsnull == closure ||        nsnull == fromRawSegment || nsCRT::strlen(fromRawSegment) < 1) {        return NS_BASE_STREAM_CLOSED;    }    *writeCount = 0;    char *headersBuf = *((char **) closure);    // pointer to where we should start copying bytes from rawSegment    char *pHeadersBuf = nsnull;    PRUint32 headersBufLen;    PRUint32 rawSegmentLen = nsCRT::strlen(fromRawSegment);    // if the buffer has no data yet    if (!headersBuf) {        headersBufLen = rawSegmentLen;        pHeadersBuf = headersBuf = (char *) nsMemory::Alloc(headersBufLen + 1);        if (!headersBuf) {            return NS_BASE_STREAM_WOULD_BLOCK;        }        memset(headersBuf, nsnull, headersBufLen + 1);    }    else {        // data has been read, reallocate        // store a pointer to the old full buffer        pHeadersBuf = headersBuf;        // create a new buffer        headersBufLen = nsCRT::strlen(headersBuf);        headersBuf =            (char *) nsMemory::Alloc(rawSegmentLen + headersBufLen + 1);        if (!headersBuf) {            headersBuf = pHeadersBuf;            pHeadersBuf = nsnull;            return NS_BASE_STREAM_WOULD_BLOCK;        }        memset(headersBuf, nsnull, rawSegmentLen + headersBufLen + 1);        // copy the old buffer to the beginning of the new buffer        memcpy(headersBuf, pHeadersBuf, headersBufLen);        // free the old buffer        nsCRT::free(pHeadersBuf);        // make the buffer pointer point to the writeable part        // of the new buffer        pHeadersBuf = headersBuf + headersBufLen;        // increment the length of the buffer        headersBufLen += rawSegmentLen;    }    // at this point, pHeadersBuf points to where we should copy bits    // from fromRawSegment.    memcpy(pHeadersBuf, fromRawSegment, rawSegmentLen);    // null termination    headersBuf[headersBufLen] = nsnull;    *((char **) closure) = headersBuf;    *writeCount = rawSegmentLen;    return NS_OK;}