logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 9d2367abf89ff202f24d72256905a869e274f9cf
parent 74cae5f40a76e87f0a0f73cfadcd97f47740e064
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun,  6 Mar 2022 16:08:31 +0100

bin/sname.c: Handle write errors

Diffstat:

Mbin/sname.c13+++++++------
Mtest-bin/sname10++++++++++
2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/bin/sname.c b/bin/sname.c @@ -2,7 +2,7 @@ // Copyright 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only -#include <stdio.h> // printf() +#include <stdio.h> // printf(), perror() #include <sys/utsname.h> // utsname, uname() int @@ -15,11 +15,12 @@ main() return 1; } - printf("sysname=%s\n", name.sysname); - printf("nodename=%s\n", name.nodename); - printf("release=%s\n", name.release); - printf("version=%s\n", name.version); - printf("machine=%s\n", name.machine); + int ret = printf("sysname=%s\nnodename=%s\nrelease=%s\nversion=%s\nmachine=%s\n", name.sysname, name.nodename, name.release, name.version, name.machine); + if(ret < 0) + { + perror("sname"); + return 1; + } return 0; } diff --git a/test-bin/sname b/test-bin/sname @@ -11,7 +11,17 @@ machine=$(uname -m) " ../bin/sname } +atf_test_case devfull +devfull_body() { + has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" + [ "$(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 -e 'inline:sname: No space left on device\n' sh -c '../bin/sname >/dev/full' +} + atf_init_test_cases() { cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case generic + atf_add_test_case devfull }