From edb8d9001cd23cfcdb0911440fdd1758e73b16dd Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Mon, 5 Mar 2007 21:34:45 +0100 Subject: [PATCH] If there is nothing to write do not even open the file for write. Patch by Alexey Tourbin. --- src/protocol/user.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/protocol/user.c b/src/protocol/user.c index 0ff3e275..be8c57b8 100644 --- a/src/protocol/user.c +++ b/src/protocol/user.c @@ -220,6 +220,7 @@ save_form_data_to_file(struct uri *uri) int fd; FILE *fp; size_t nmemb; + unsigned char *formdata; if (!filename) return NULL; @@ -229,6 +230,8 @@ save_form_data_to_file(struct uri *uri) return NULL; } + if (!uri->post) return filename; + fp = fdopen(fd, "w"); if (!fp) { @@ -239,16 +242,14 @@ error: return NULL; } - if (uri->post) { - /* Jump the content type */ - unsigned char *formdata = strchr(uri->post, '\n'); + /* Jump the content type */ + formdata = strchr(uri->post, '\n'); + formdata = formdata ? formdata + 1 : uri->post; - formdata = formdata ? formdata + 1 : uri->post; - nmemb = fwrite(formdata, strlen(formdata), 1, fp); - if (nmemb != 1) { - fclose(fp); - goto error; - } + nmemb = fwrite(formdata, strlen(formdata), 1, fp); + if (nmemb != 1) { + fclose(fp); + goto error; } if (fclose(fp) != 0)