From ad1b9e767d5f13df6602f669fb5b3349e5f492bd Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Sat, 11 Feb 2023 20:38:25 -0500
Subject: [PATCH v4 5/5] Open output file in binary mode.

This is to keep pg_bsd_indent from inserting Windows-style newlines
on Windows systems.  Per cfbot.

Discussion: https://postgr.es/m/734490.1676165550@sss.pgh.pa.us
---
 src/tools/pg_bsd_indent/indent.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/tools/pg_bsd_indent/indent.c b/src/tools/pg_bsd_indent/indent.c
index 34205f2ead..2fd8771083 100644
--- a/src/tools/pg_bsd_indent/indent.c
+++ b/src/tools/pg_bsd_indent/indent.c
@@ -207,7 +207,7 @@ main(int argc, char **argv)
 							 * the file */
 		    errx(1, "input and output files must be different");
 		}
-		output = fopen(out_name, "w");
+		output = fopen(out_name, "wb");
 		if (output == NULL)	/* check for create error */
 			err(1, "%s", out_name);
 		continue;
@@ -1232,7 +1232,7 @@ bakcopy(void)
     if (input == NULL)
 	err(1, "%s", bakfile);
     /* now the original input file will be the output */
-    output = fopen(in_name, "w");
+    output = fopen(in_name, "wb");
     if (output == NULL) {
 	unlink(bakfile);
 	err(1, "%s", in_name);
-- 
2.31.1

