tweaks: rename two variables, and add a third, for more contrast
This commit is contained in:
parent
022cc084a7
commit
e3807f00a2
42
src/files.c
42
src/files.c
@ -1719,10 +1719,10 @@ bool write_file(const char *name, FILE *stream, bool tmp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
/* If we're prepending, copy the file to a temp file. */
|
/* When prepending, first copy the existing file to a temporary file. */
|
||||||
if (method == PREPEND) {
|
if (method == PREPEND) {
|
||||||
int fd_source;
|
int fd_src;
|
||||||
FILE *f_source = NULL;
|
FILE *source = NULL, *target = NULL;
|
||||||
|
|
||||||
if (fopen(realname, "rb") == NULL) {
|
if (fopen(realname, "rb") == NULL) {
|
||||||
statusline(ALERT, _("Error reading %s: %s"), realname,
|
statusline(ALERT, _("Error reading %s: %s"), realname,
|
||||||
@ -1730,7 +1730,7 @@ bool write_file(const char *name, FILE *stream, bool tmp,
|
|||||||
goto cleanup_and_exit;
|
goto cleanup_and_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
tempname = safe_tempfile(&f);
|
tempname = safe_tempfile(&target);
|
||||||
|
|
||||||
if (tempname == NULL) {
|
if (tempname == NULL) {
|
||||||
statusline(ALERT, _("Error writing temp file: %s"),
|
statusline(ALERT, _("Error writing temp file: %s"),
|
||||||
@ -1738,21 +1738,21 @@ bool write_file(const char *name, FILE *stream, bool tmp,
|
|||||||
goto cleanup_and_exit;
|
goto cleanup_and_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd_source = open(realname, O_RDONLY);
|
fd_src = open(realname, O_RDONLY);
|
||||||
|
|
||||||
if (fd_source != -1) {
|
if (fd_src != -1) {
|
||||||
f_source = fdopen(fd_source, "rb");
|
source = fdopen(fd_src, "rb");
|
||||||
if (f_source == NULL) {
|
if (source == NULL) {
|
||||||
statusline(ALERT, _("Error reading %s: %s"), realname,
|
statusline(ALERT, _("Error reading %s: %s"), realname,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
close(fd_source);
|
close(fd_src);
|
||||||
fclose(f);
|
fclose(target);
|
||||||
unlink(tempname);
|
unlink(tempname);
|
||||||
goto cleanup_and_exit;
|
goto cleanup_and_exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f_source == NULL || copy_file(f_source, f, TRUE) != 0) {
|
if (source == NULL || copy_file(source, target, TRUE) != 0) {
|
||||||
statusline(ALERT, _("Error writing temp file: %s"),
|
statusline(ALERT, _("Error writing temp file: %s"),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
unlink(tempname);
|
unlink(tempname);
|
||||||
@ -1859,27 +1859,27 @@ bool write_file(const char *name, FILE *stream, bool tmp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
/* If we're prepending, open the temp file, and append it to f. */
|
/* When prepending, append the temporary file to what we wrote above. */
|
||||||
if (method == PREPEND) {
|
if (method == PREPEND) {
|
||||||
int fd_source;
|
int fd_src;
|
||||||
FILE *f_source = NULL;
|
FILE *source = NULL;
|
||||||
|
|
||||||
fd_source = open(tempname, O_RDONLY);
|
fd_src = open(tempname, O_RDONLY);
|
||||||
|
|
||||||
if (fd_source != -1) {
|
if (fd_src != -1) {
|
||||||
f_source = fdopen(fd_source, "rb");
|
source = fdopen(fd_src, "rb");
|
||||||
if (f_source == NULL)
|
if (source == NULL)
|
||||||
close(fd_source);
|
close(fd_src);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f_source == NULL) {
|
if (source == NULL) {
|
||||||
statusline(ALERT, _("Error reading %s: %s"), tempname,
|
statusline(ALERT, _("Error reading %s: %s"), tempname,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
fclose(f);
|
fclose(f);
|
||||||
goto cleanup_and_exit;
|
goto cleanup_and_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_file(f_source, f, TRUE) != 0) {
|
if (copy_file(source, f, TRUE) != 0) {
|
||||||
statusline(ALERT, _("Error writing %s: %s"), realname,
|
statusline(ALERT, _("Error writing %s: %s"), realname,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto cleanup_and_exit;
|
goto cleanup_and_exit;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user