1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-02-02 15:09:23 -05:00

save_textarea_file(): do not open file for writing if not needed. Patch

by Alexey Tourbin.
This commit is contained in:
Laurent MONIN 2007-03-05 21:48:42 +01:00 committed by Laurent MONIN
parent ecce8bfa91
commit 86686983c0

View File

@ -534,7 +534,7 @@ save_textarea_file(unsigned char *value)
unsigned char *filename; unsigned char *filename;
FILE *fp = NULL; FILE *fp = NULL;
int fd; int fd;
size_t nmemb; size_t nmemb, len;
filename = get_tempdir_filename("elinks-area-XXXXXX"); filename = get_tempdir_filename("elinks-area-XXXXXX");
if (!filename) return NULL; if (!filename) return NULL;
@ -545,6 +545,9 @@ save_textarea_file(unsigned char *value)
return NULL; return NULL;
} }
len = strlen(value);
if (len == 0) return filename;
fp = fdopen(fd, "w"); fp = fdopen(fd, "w");
if (!fp) { if (!fp) {
@ -555,7 +558,7 @@ error:
return NULL; return NULL;
} }
nmemb = fwrite(value, strlen(value), 1, fp); nmemb = fwrite(value, len, 1, fp);
if (nmemb != 1) { if (nmemb != 1) {
fclose(fp); fclose(fp);
goto error; goto error;