nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(strm); NS_ASSERTION(safeStream, "expected a safe output stream!"); if (NS_SUCCEEDED(rv) && safeStream) rv = safeStream->Finish();  if (NS_FAILED(rv)) { NS_WARNING("failed to save bookmarks file! possible dataloss"); return rv; }  mDirty = PR_FALSE; return NS_OK;
strm << "<TITLE>Bookmarks</TITLE>\n"; strm << "<H1>Bookmarks</H1>\n\n";  rv = WriteBookmarksContainer(ds, strm, root, 0); } return(rv);
nsBookmarksService::WriteBookmarks(nsIFile* aBookmarksFile,                                   nsIRDFDataSource* aDataSource,                                   nsIRDFResource *aRoot){    if (!aBookmarksFile || !aDataSource || !aRoot)        return NS_ERROR_NULL_POINTER;    // get a safe output stream, so we don't clobber the bookmarks file unless    // all the writes succeeded.    nsCOMPtr<nsIOutputStream> out;    nsresult rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(out),                                                  aBookmarksFile,                                                  -1,                                                  /*octal*/ 0600);    if (NS_FAILED(rv)) return rv;    // We need a buffered output stream for performance.    // See bug 202477.    nsCOMPtr<nsIOutputStream> strm;    rv = NS_NewBufferedOutputStream(getter_AddRefs(strm), out, 4096);    if (NS_FAILED(rv)) return rv;    PRUint32 dummy;    strm->Write(kFileIntro, sizeof(kFileIntro)-1, &dummy);    nsCOMArray<nsIRDFResource> parentArray;    rv = WriteBookmarksContainer(aDataSource, strm, aRoot, 0, parentArray);    // All went ok. Maybe except for problems in Write(), but the stream detects    // that for us    nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(strm);    NS_ASSERTION(safeStream, "expected a safe output stream!");    if (NS_SUCCEEDED(rv) && safeStream)        rv = safeStream->Finish();    if (NS_FAILED(rv)) {        NS_WARNING("failed to save bookmarks file! possible dataloss");        return rv;    }    mDirty = PR_FALSE;    return NS_OK;}