commit: 5655c484f39f374f46f38a788bbf737ea07fc5e1
parent 76d270ac1f8eb8981aae33047387786969e89047
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue,  1 Mar 2022 20:07:09 +0100
bin/errno: Handle write errors
Diffstat:
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/bin/errno.c b/bin/errno.c
@@ -25,7 +25,10 @@ main(int argc, char *argv[])
 		return 1;
 	}
 
-	puts(strerror(err));
+	if(puts(strerror(err)) <= 0)
+	{
+		return 1;
+	}
 
 	return 0;
 }
diff --git a/test-bin/errno b/test-bin/errno
@@ -10,8 +10,21 @@ noargs_body() {
 	atf_check -s exit:1 -o "inline:usage: errno <number>\n" ../bin/errno
 }
 
+atf_test_case devfull
+devfull_body() {
+	if test -f /usr/include/features.h && grep -q '#define\W__GLIBC__' /usr/include/features.h
+	then
+		atf_expect_fail "glibc ignoring write errors for puts()"
+	fi
+	[ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()"
+	[ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()"
+
+	atf_check -s exit:1 -o "inline:usage: errno <number>\n" sh -c '../bin/errno 1 >/dev/full'
+}
+
 atf_init_test_cases() {
 	cd "$(atf_get_srcdir)" || exit 1
 	atf_add_test_case simple
 	atf_add_test_case noargs
+	atf_add_test_case devfull
 }