NS_NewLocalFileOutputStream(getter_AddRefs(strm), dirSpec);
rv = NS_NewLocalFileOutputStream(getter_AddRefs(strm), dirSpec); if (NS_FAILED(rv)) { return rv; }
COOKIE_Write() {  if (!cookie_changed) {    return NS_OK;  }  cookie_CookieStruct * cookie_s;  time_t cur_date = get_current_time();  char date_string[36];  nsCOMPtr<nsIFile> dirSpec;  nsresult rv;  rv = CKutil_ProfileDirectory(getter_AddRefs(dirSpec));  if (NS_FAILED(rv)) {    return rv;  }  dirSpec->AppendNative(NS_LITERAL_CSTRING(kCookiesFileName));  nsCOMPtr<nsIOutputStream> strm;  NS_NewLocalFileOutputStream(getter_AddRefs(strm),                              dirSpec);#define COOKIEFILE_LINE1 "# HTTP Cookie File\n"#define COOKIEFILE_LINE2 "# http://www.netscape.com/newsref/std/cookie_spec.html\n"#define COOKIEFILE_LINE3 "# This is a generated file!  Do not edit.\n"#define COOKIEFILE_LINE4 "# To delete cookies, use the Cookie Manager.\n\n"  PRUint32 ignore;  strm->Write(COOKIEFILE_LINE1, sizeof(COOKIEFILE_LINE1)-1, &ignore);  strm->Write(COOKIEFILE_LINE2, sizeof(COOKIEFILE_LINE2)-1, &ignore);  strm->Write(COOKIEFILE_LINE3, sizeof(COOKIEFILE_LINE3)-1, &ignore);  strm->Write(COOKIEFILE_LINE4, sizeof(COOKIEFILE_LINE4)-1, &ignore);  /* format shall be:   *   * host \t isDomain \t path \t secure \t expires \t name \t cookie   *   * isDomain is PR_TRUE or PR_FALSE   * secure is PR_TRUE or PR_FALSE   * expires is a time_t integer   * cookie can have tabs   */  PRInt32 count = cookie_list ? cookie_list->Count() : 0;  for (PRInt32 i = 0; i < count; ++i) {    cookie_s = NS_STATIC_CAST(cookie_CookieStruct*, cookie_list->ElementAt(i));    NS_ASSERTION(cookie_s, "corrupt cookie list");     if (cookie_s->expires < cur_date || cookie_s->status == nsICookie::STATUS_DOWNGRADED) {       /* don't write entry if cookie has expired, has no expiratio date, or has been downgraded */        continue;      }      strm->Write(cookie_s->host.get(), cookie_s->host.Length(), &ignore);      if (cookie_s->isDomain) {        strm->Write("\tTRUE\t", 6, &ignore);      } else {        strm->Write("\tFALSE\t", 7, &ignore);      }      strm->Write(cookie_s->path.get(), cookie_s->path.Length(), &ignore);      if (cookie_s->isSecure) {        strm->Write("\tTRUE\t", 6, &ignore);      } else {        strm->Write("\tFALSE\t", 7, &ignore);      }      PR_snprintf(date_string, sizeof(date_string), "%lu", NS_STATIC_CAST(unsigned long, cookie_s->expires));      strm->Write(date_string, strlen(date_string), &ignore);      strm->Write("\t", 1, &ignore);      strm->Write(cookie_s->name.get(), cookie_s->name.Length(), &ignore);      strm->Write("\t", 1, &ignore);      strm->Write(cookie_s->cookie.get(), cookie_s->cookie.Length(), &ignore);      strm->Write("\n", 1, &ignore);  }  cookie_changed = PR_FALSE;  return NS_OK;}