From b9de5525c4f61ed10af9c0552c4562c41c695f47 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@telfort.nl>
Date: Thu, 22 Mar 2018 10:41:39 +0100
Subject: [PATCH] tweaks: elide a parameter, as it's always the inverse of
 another

---
 src/files.c | 19 ++++++++-----------
 src/nano.c  |  2 +-
 src/proto.h |  3 +--
 src/text.c  |  2 +-
 4 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/src/files.c b/src/files.c
index 60ce1b13..4c27f46c 100644
--- a/src/files.c
+++ b/src/files.c
@@ -476,7 +476,7 @@ bool open_buffer(const char *filename, bool new_buffer)
 	/* If we have a non-new file, read it in.  Then, if the buffer has
 	 * no stat, update the stat, if applicable. */
 	if (rc > 0) {
-		read_file(f, rc, realname, !new_buffer, new_buffer);
+		read_file(f, rc, realname, !new_buffer);
 #ifndef NANO_TINY
 		if (openfile->current_stat == NULL)
 			stat_with_alloc(realname, &openfile->current_stat);
@@ -522,7 +522,7 @@ void replace_buffer(const char *filename)
 	initialize_buffer_text();
 
 	/* Insert the processed file into its place. */
-	read_file(f, descriptor, filename, FALSE, TRUE);
+	read_file(f, descriptor, filename, FALSE);
 
 	/* Put current at a place that is certain to exist. */
 	openfile->current = openfile->fileage;
@@ -553,7 +553,7 @@ void replace_marked_buffer(const char *filename, filestruct *top, size_t top_x,
 	 * where the marked text was. */
 	extract_buffer(&trash_top, &trash_bot, top, top_x, bot, bot_x);
 	free_filestruct(trash_top);
-	read_file(f, descriptor, filename, FALSE, TRUE);
+	read_file(f, descriptor, filename, FALSE);
 
 	/* Restore the magicline behavior now that we're done fiddling. */
 	if (!old_no_newlines)
@@ -710,13 +710,10 @@ char *encode_data(char *buf, size_t buf_len)
 	return mallocstrcpy(NULL, buf);
 }
 
-/* Read an open file into the current buffer.  f should be set to the
- * open file, and filename should be set to the name of the file.
- * undoable means do we want to create undo records to try and undo
- * this.  Will also attempt to check file writability if fd > 0 and
- * checkwritable == TRUE. */
-void read_file(FILE *f, int fd, const char *filename, bool undoable,
-				bool checkwritable)
+/* Read the given open file f into the current buffer.  filename should be
+ * set to the name of the file.  undoable means that undo records should be
+ * created and that the file does not need to be checked for writability. */
+void read_file(FILE *f, int fd, const char *filename, bool undoable)
 {
 	ssize_t was_lineno = openfile->current->lineno;
 		/* The line number where we start the insertion. */
@@ -832,7 +829,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable,
 	if (ferror(f))
 		nperror(filename);
 	fclose(f);
-	if (fd > 0 && checkwritable) {
+	if (fd > 0 && !undoable) {
 		close(fd);
 		writable = is_file_writable(filename);
 	}
diff --git a/src/nano.c b/src/nano.c
index 9db58f07..e7157e6f 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1171,7 +1171,7 @@ bool scoop_stdin(void)
 
 	/* Read the input into a new buffer. */
 	open_buffer("", TRUE);
-	read_file(stream, 0, "stdin", TRUE, FALSE);
+	read_file(stream, 0, "stdin", TRUE);
 	openfile->edittop = openfile->fileage;
 
 	/* Reconnect the tty as the input source. */
diff --git a/src/proto.h b/src/proto.h
index f8c04262..2d6ebfc1 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -281,8 +281,7 @@ void switch_to_prev_buffer(void);
 void switch_to_next_buffer(void);
 bool close_buffer(void);
 #endif
-void read_file(FILE *f, int fd, const char *filename, bool undoable,
-				bool checkwritable);
+void read_file(FILE *f, int fd, const char *filename, bool undoable);
 int open_file(const char *filename, bool newfie, bool quiet, FILE **f);
 char *get_next_filename(const char *name, const char *suffix);
 void do_insertfile_void(void);
diff --git a/src/text.c b/src/text.c
index 8e3843d3..da0b10b5 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1149,7 +1149,7 @@ bool execute_command(const char *command)
 	if (f == NULL)
 		nperror("fdopen");
 
-	read_file(f, 0, "stdin", TRUE, FALSE);
+	read_file(f, 0, "stdin", TRUE);
 
 	if (wait(NULL) == -1)
 		nperror("wait");
-- 
GitLab