nsOutputFileStream strm(dirSpec + kCookiesFileName);
dirSpec += kCookiesFileName; PRBool ignored; dirSpec.ResolveSymlink(ignored); nsOutputFileStream strm(dirSpec);
COOKIE_Write(nsIFile* dir) {  if (!cookie_changed) {    return NS_OK;  }  cookie_CookieStruct * cookie_s;  time_t cur_date = get_current_time();  char date_string[36];  nsFileSpec dirSpec;  nsCOMPtr<nsIFileSpec> dirSpec0;  nsresult rv;  if (dir == nsnull) {    rv = CKutil_ProfileDirectory(dirSpec);    if (NS_FAILED(rv)) {      return rv;    }  } else {    rv = NS_NewFileSpecFromIFile(dir, getter_AddRefs(dirSpec0));    if (NS_FAILED(rv)) {      return rv;    }    rv = dirSpec0->GetFileSpec(&dirSpec);  }  nsOutputFileStream strm(dirSpec + kCookiesFileName);  if (!strm.is_open()) {    /* file doesn't exist -- that's not an error */    return NS_OK;  }#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"  strm.write(COOKIEFILE_LINE1, PL_strlen(COOKIEFILE_LINE1));  strm.write(COOKIEFILE_LINE2, PL_strlen(COOKIEFILE_LINE2));  strm.write(COOKIEFILE_LINE3, PL_strlen(COOKIEFILE_LINE3));  strm.write(COOKIEFILE_LINE4, PL_strlen(COOKIEFILE_LINE4));  /* 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, strlen(cookie_s->host));      if (cookie_s->isDomain) {        strm.write("\tTRUE\t", 6);      } else {        strm.write("\tFALSE\t", 7);      }      strm.write(cookie_s->path, strlen(cookie_s->path));      if (cookie_s->isSecure) {        strm.write("\tTRUE\t", 6);      } else {        strm.write("\tFALSE\t", 7);      }      PR_snprintf(date_string, sizeof(date_string), "%lu", NS_STATIC_CAST(unsigned long, cookie_s->expires));      strm.write(date_string, strlen(date_string));      strm.write("\t", 1);      strm.write(cookie_s->name, strlen(cookie_s->name));      strm.write("\t", 1);      strm.write(cookie_s->cookie, strlen(cookie_s->cookie));      strm.write("\n", 1);  }  cookie_changed = PR_FALSE;  strm.flush();  strm.close();  return NS_OK;}