diff util-src/pposix.c @ 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 f29d15aef6f8
children 151babd0853b 573ac422ca1d
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()) {