rv = NS_ERROR_NOT_AVAILABLE;
GetTypeAndDescriptionFromMimetypesFile(const nsAString& aFilename,                                       const nsAString& aFileExtension,                                       nsAString& aMajorType,                                       nsAString& aMinorType,                                       nsAString& aDescription) {  nsresult rv = NS_OK;  nsCOMPtr<nsIFileInputStream> mimeFile;  nsCOMPtr<nsILineInputStream> mimeTypes;  PRBool netscapeFormat;  nsAutoString buf;  PRBool more = PR_FALSE;  rv = CreateInputStream(aFilename, getter_AddRefs(mimeFile), getter_AddRefs(mimeTypes),                         buf, &netscapeFormat, &more);  if (NS_FAILED(rv)) {    return rv;  }    nsAutoString extensions;  nsString entry;  entry.SetCapacity(100);  nsAString::const_iterator majorTypeStart, majorTypeEnd,                            minorTypeStart, minorTypeEnd,                            descriptionStart, descriptionEnd;  do {    // read through, building up an entry.  If we finish an entry, check for    // a match and return out of the loop if we match    // skip comments and empty lines    if (!buf.IsEmpty() && buf.First() != '#') {      entry.Append(buf);      if (entry.Last() == '\\') {        entry.Truncate(entry.Length() - 1);        entry.Append(PRUnichar(' '));  // in case there is no trailing whitespace on this line      } else {  // we have a full entry        if (netscapeFormat) {          rv = ParseNetscapeMIMETypesEntry(entry,                                           majorTypeStart, majorTypeEnd,                                           minorTypeStart, minorTypeEnd,                                           extensions,                                           descriptionStart, descriptionEnd);          if (NS_FAILED(rv)) {            // We sometimes get things like RealPlayer sticking            // "normal" entries in "Netscape" .mime.types files.  Try            // to handle that.  Bug 106381            rv = ParseNormalMIMETypesEntry(entry,                                           majorTypeStart, majorTypeEnd,                                           minorTypeStart, minorTypeEnd,                                           extensions,                                           descriptionStart, descriptionEnd);          }        } else {          rv = ParseNormalMIMETypesEntry(entry,                                         majorTypeStart, majorTypeEnd,                                         minorTypeStart, minorTypeEnd,                                         extensions,                                         descriptionStart, descriptionEnd);                  }#ifdef DEBUG_bzbarsky        if (NS_FAILED(rv)) {          fprintf(stderr, "Failed to parse entry: %s\n", NS_ConvertUCS2toUTF8(entry).get());        }#endif        if (NS_SUCCEEDED(rv)) { // entry parses          nsAString::const_iterator start, end;          extensions.BeginReading(start);          extensions.EndReading(end);          nsAString::const_iterator iter(start);          while (start != end) {            FindCharInReadable(',', iter, end);            if (Substring(start, iter).Equals(aFileExtension,                                              nsCaseInsensitiveStringComparator())) {              // it's a match.  Assign the type and description and run              aMajorType.Assign(Substring(majorTypeStart, majorTypeEnd));              aMinorType.Assign(Substring(minorTypeStart, minorTypeEnd));              aDescription.Assign(Substring(descriptionStart, descriptionEnd));              mimeFile->Close();              return NS_OK;            }            if (iter != end) {              ++iter;            }            start = iter;          }        }        // truncate the entry for the next iteration        entry.Truncate();      }    }    if (!more) {      break;    }    // read the next line    rv = mimeTypes->ReadLine(buf, &more);  } while (NS_SUCCEEDED(rv));  mimeFile->Close();  return rv;}