nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit eb757e7c5b40157ddd11e994d9f45b7473adbf9a
parent b5546060470138a9d39d7f646ded96857200ac0f
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Thu, 17 Oct 2019 12:08:50 +0200

tweaks: simplify the opening of files when prepending

There is no need for a file descriptor: all reading and writing
is done on streams.

Diffstat:
Msrc/files.c | 23+++--------------------
1 file changed, 3 insertions(+), 20 deletions(-)

diff --git a/src/files.c b/src/files.c @@ -1711,16 +1711,8 @@ bool write_file(const char *name, FILE *stream, bool tmp, #ifndef NANO_TINY /* When prepending, first copy the existing file to a temporary file. */ if (method == PREPEND) { - int fd_src; - FILE *source = NULL, *target = NULL; - - fd_src = open(realname, O_RDONLY); - - if (fd_src != -1) { - source = fdopen(fd_src, "rb"); - if (source == NULL) - close(fd_src); - } + FILE *source = fopen(realname, "rb"); + FILE *target = NULL; if (source == NULL) { statusline(ALERT, _("Error reading %s: %s"), realname, @@ -1846,16 +1838,7 @@ bool write_file(const char *name, FILE *stream, bool tmp, #ifndef NANO_TINY /* When prepending, append the temporary file to what we wrote above. */ if (method == PREPEND) { - int fd_src; - FILE *source = NULL; - - fd_src = open(tempname, O_RDONLY); - - if (fd_src != -1) { - source = fdopen(fd_src, "rb"); - if (source == NULL) - close(fd_src); - } + FILE *source = fopen(tempname, "rb"); if (source == NULL) { statusline(ALERT, _("Error reading %s: %s"), tempname,