static bool save_complete_save_html_document(save_complete_ctx *ctx, hlcache_handle *c, bool index) { nserror ret; FILE *fp; char *fname = NULL; dom_document *doc; lwc_string *mime_type; char filename[32]; if (index) { snprintf(filename, sizeof filename, "index"); } else { snprintf(filename, sizeof filename, "%p", c); } ret = netsurf_mkpath(&fname, NULL, 2, ctx->path, filename); if (ret != NSERROR_OK) { guit->misc->warning(messages_get_errorcode(ret), NULL); return false; } fp = fopen(fname, "wb"); if (fp == NULL) { free(fname); LOG("fopen(): errno = %i", errno); guit->misc->warning("SaveError", strerror(errno)); return false; } ctx->base = html_get_base_url(c); ctx->fp = fp; ctx->iter_state = STATE_NORMAL; doc = html_get_document(c); if (save_complete_libdom_treewalk((dom_node *) doc, save_complete_node_handler, ctx) == false) { free(fname); guit->misc->warning("NoMemory", 0); fclose(fp); return false; } fclose(fp); mime_type = content_get_mime_type(c); if (mime_type != NULL) { if (ctx->set_type != NULL) ctx->set_type(fname, mime_type); lwc_string_unref(mime_type); } free(fname); return true; }
static bool save_complete_save_html_document(save_complete_ctx *ctx, hlcache_handle *c, bool index) { bool error; FILE *fp; dom_document *doc; lwc_string *mime_type; char filename[32]; char fullpath[PATH_MAX]; strncpy(fullpath, ctx->path, sizeof fullpath); if (index) snprintf(filename, sizeof filename, "index"); else snprintf(filename, sizeof filename, "%p", c); error = path_add_part(fullpath, sizeof fullpath, filename); if (error == false) { warn_user("NoMemory", NULL); return false; } fp = fopen(fullpath, "wb"); if (fp == NULL) { warn_user("NoMemory", NULL); return false; } ctx->base = html_get_base_url(c); ctx->fp = fp; ctx->iter_state = STATE_NORMAL; doc = html_get_document(c); if (save_complete_libdom_treewalk((dom_node *) doc, save_complete_node_handler, ctx) == false) { warn_user("NoMemory", 0); fclose(fp); return false; } fclose(fp); mime_type = content_get_mime_type(c); if (mime_type != NULL) { if (ctx->set_type != NULL) ctx->set_type(fullpath, mime_type); lwc_string_unref(mime_type); } return true; }