1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-30 03:26:23 -04:00

If there is nothing to write do not even open the file for write. Patch

by Alexey Tourbin.
This commit is contained in:
Laurent MONIN 2007-03-05 21:34:45 +01:00 committed by Laurent MONIN
parent 4b9ddf1481
commit edb8d9001c

View File

@ -220,6 +220,7 @@ save_form_data_to_file(struct uri *uri)
int fd; int fd;
FILE *fp; FILE *fp;
size_t nmemb; size_t nmemb;
unsigned char *formdata;
if (!filename) return NULL; if (!filename) return NULL;
@ -229,6 +230,8 @@ save_form_data_to_file(struct uri *uri)
return NULL; return NULL;
} }
if (!uri->post) return filename;
fp = fdopen(fd, "w"); fp = fdopen(fd, "w");
if (!fp) { if (!fp) {
@ -239,17 +242,15 @@ error:
return NULL; return NULL;
} }
if (uri->post) {
/* Jump the content type */ /* Jump the content type */
unsigned char *formdata = strchr(uri->post, '\n'); formdata = strchr(uri->post, '\n');
formdata = formdata ? formdata + 1 : uri->post; formdata = formdata ? formdata + 1 : uri->post;
nmemb = fwrite(formdata, strlen(formdata), 1, fp); nmemb = fwrite(formdata, strlen(formdata), 1, fp);
if (nmemb != 1) { if (nmemb != 1) {
fclose(fp); fclose(fp);
goto error; goto error;
} }
}
if (fclose(fp) != 0) if (fclose(fp) != 0)
goto error; goto error;