changeset 14054:904932fc525f 13.0

util.pposix: Silence compiler warnings about unused return values ast-grep run -p 'freopen("/dev/null", $A, $B);' -r 'if(!freopen("/dev/null", $A, $B)) { fprintf(stderr, "Failed to redirect $B to /dev/null"); }' Thanks Victor Seva
author Kim Alvefur <zash@zash.se>
date Sun, 01 Feb 2026 14:49:34 +0100
parents ea71767067f7
children f47b4baa7934
files util-src/pposix.c
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/util-src/pposix.c	Thu Jan 22 10:23:22 2026 +0000
+++ b/util-src/pposix.c	Sun Feb 01 14:49:34 2026 +0100
@@ -123,9 +123,17 @@
 	}
 
 	/* Make sure accidental use of FDs 0, 1, 2 don't cause weirdness */
-	freopen("/dev/null", "r", stdin);
-	freopen("/dev/null", "w", stdout);
-	freopen("/dev/null", "w", stderr);
+	if(!freopen("/dev/null", "r", stdin)) {
+		fprintf(stderr, "Failed to redirect stdin to /dev/null");
+	}
+
+	if(!freopen("/dev/null", "w", stdout)) {
+		fprintf(stderr, "Failed to redirect stdout to /dev/null");
+	}
+
+	if(!freopen("/dev/null", "w", stderr)) {
+		fprintf(stderr, "Failed to redirect stderr to /dev/null");
+	}
 
 	/* Final fork, use it wisely */
 	if(fork()) {