char eolchar;
char eolchar = '\0';
NS_ReadLine (nsIInputStream* aStream, nsLineBuffer * aBuffer,             nsAWritableString & aLine, PRBool *more) {  nsresult rv = NS_OK;  PRUint32 bytesRead;  nsAutoString temp;  *more = PR_TRUE;  PRBool eolStarted = PR_FALSE;  char eolchar;  aLine.Truncate();  while (1) { // will be returning out of this loop on eol or eof    if (aBuffer->empty) { // buffer is empty.  Read into it.      rv = aStream->Read(aBuffer->buf, kLineBufferSize, &bytesRead);      if (NS_FAILED(rv)) // read failed        return rv;      if (bytesRead == 0) { // end of file        *more = PR_FALSE;        return NS_OK;      }      aBuffer->end = aBuffer->buf + bytesRead;      aBuffer->empty = PR_FALSE;      *(aBuffer->end) = '\0'; // null-terminate this thing    }    // walk the buffer looking for an end-of-line    while (aBuffer->current < aBuffer->end) {      if (eolStarted) {          if ((eolchar == '\n' && *(aBuffer->current) == '\r') ||              (eolchar == '\r' && *(aBuffer->current) == '\n')) { // line end            (aBuffer->current)++;            aBuffer->start = aBuffer->current;          }          eolStarted = PR_FALSE;          return NS_OK;      } else if (*(aBuffer->current) == '\n' ||                 *(aBuffer->current) == '\r') { // line end        eolStarted = PR_TRUE;        eolchar = *(aBuffer->current);        *(aBuffer->current) = '\0';        temp.AssignWithConversion(aBuffer->start);        aLine.Append(temp);        (aBuffer->current)++;        aBuffer->start = aBuffer->current;      } else {        eolStarted = PR_FALSE;        (aBuffer->current)++;      }    }    // append whatever we currently have to the string    temp.AssignWithConversion(aBuffer->start);    aLine.Append(temp);    // we've run out of buffer.  Begin anew    aBuffer->current = aBuffer->start = aBuffer->buf;    aBuffer->empty = PR_TRUE;        if (eolStarted) {  // have to read another char and possibly skip over it      rv = aStream->Read(aBuffer->buf, 1, &bytesRead);      if (NS_FAILED(rv)) // read failed        return rv;      if (bytesRead == 0) { // end of file        *more = PR_FALSE;        return NS_OK;      }      if ((eolchar == '\n' && *(aBuffer->buf) == '\r') ||          (eolchar == '\r' && *(aBuffer->buf) == '\n')) {        // Just return and all is good -- we've skipped the extra newline char        return NS_OK;      } else {        // we have a byte that we should look at later        aBuffer->empty = PR_FALSE;        aBuffer->end = aBuffer->buf + 1;        *(aBuffer->end) = '\0';      }    }  }}