git: ffd41d39c660 - main - sort: simplify file_reader_clean

From: Baptiste Daroussin <bapt_at_FreeBSD.org>
Date: Thu, 13 Oct 2022 08:42:56 UTC
The branch main has been updated by bapt:

URL: https://cgit.FreeBSD.org/src/commit/?id=ffd41d39c660ca1c80b77707238e8e5ef26d7d7a

commit ffd41d39c660ca1c80b77707238e8e5ef26d7d7a
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2022-10-13 08:40:21 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2022-10-13 08:42:23 +0000

    sort: simplify file_reader_clean
    
    Deindent the function, remove useless tests:
     - free already test if argument is NULL
     - closefile already test if the input is stdin or null
---
 usr.bin/sort/file.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/usr.bin/sort/file.c b/usr.bin/sort/file.c
index 8f9d8ac89b5b..0f1a9e6bad4d 100644
--- a/usr.bin/sort/file.c
+++ b/usr.bin/sort/file.c
@@ -574,7 +574,7 @@ openfile(const char *fn, const char *mode)
 void
 closefile(FILE *f, const char *fn)
 {
-	if (f == NULL || f = stdin)
+	if (f == NULL || f == stdin)
 		return;
 	if (f == stdout) {
 		fflush(f);
@@ -699,25 +699,18 @@ static void
 file_reader_clean(struct file_reader *fr)
 {
 
-	if (fr) {
-		if (fr->mmapaddr)
-			munmap(fr->mmapaddr, fr->mmapsize);
-
-		if (fr->fd)
-			close(fr->fd);
-
-		if (fr->buffer)
-			sort_free(fr->buffer);
-
-		if (fr->file)
-			if (fr->file != stdin)
-				closefile(fr->file, fr->fname);
+	if (fr == NULL)
+		return;
 
-		if(fr->fname)
-			sort_free(fr->fname);
+	if (fr->mmapaddr)
+		munmap(fr->mmapaddr, fr->mmapsize);
+	if (fr->fd)
+		close(fr->fd);
 
-		memset(fr, 0, sizeof(struct file_reader));
-	}
+	free(fr->buffer);
+	closefile(fr->file, fr->fname);
+	free(fr->fname);
+	memset(fr, 0, sizeof(struct file_reader));
 }
 
 void