logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 76d270ac1f8eb8981aae33047387786969e89047
parent 21dc297b514fc1b20c99184095c8625adf6c90a3
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue,  1 Mar 2022 19:59:47 +0100

bin/errno: New

Diffstat:

Abin/errno.c31+++++++++++++++++++++++++++++++
Mtest-bin/Kyuafile1+
Atest-bin/errno17+++++++++++++++++
3 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/bin/errno.c b/bin/errno.c @@ -0,0 +1,31 @@ +// Collection of Unix tools, comparable to coreutils +// Copyright 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +#include <errno.h> // errno +#include <stdio.h> // puts, perror +#include <stdlib.h> // strtol +#include <string.h> // strerror + +int +main(int argc, char *argv[]) +{ + if(argc != 2) + { + puts("usage: errno <number>"); + return 1; + } + + errno = 0; + + int err = (int)(strtol(argv[1], NULL, 10)); + if(errno != 0) + { + perror("errno: strtol"); + return 1; + } + + puts(strerror(err)); + + return 0; +} diff --git a/test-bin/Kyuafile b/test-bin/Kyuafile @@ -13,6 +13,7 @@ atf_test_program{name="del", required_files=basedir.."/bin/del"} atf_test_program{name="dirname", required_files=basedir.."/bin/dirname"} atf_test_program{name="echo", required_files=basedir.."/bin/echo"} atf_test_program{name="env", required_files=basedir.."/bin/env"} +atf_test_program{name="errno", required_files=basedir.."/bin/errno"} atf_test_program{name="false", required_files=basedir.."/bin/false"} atf_test_program{name="humanize", required_files=basedir.."/bin/humanize"} atf_test_program{name="mdate", required_files=basedir.."/bin/mdate"} diff --git a/test-bin/errno b/test-bin/errno @@ -0,0 +1,17 @@ +#!/usr/bin/env atf-sh +atf_test_case simple +simple_body() { + atf_check -o "inline:Success\n" ../bin/errno 0 + atf_check -o "inline:Operation not permitted\n" ../bin/errno 1 +} + +atf_test_case noargs +noargs_body() { + atf_check -s exit:1 -o "inline:usage: errno <number>\n" ../bin/errno +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case simple + atf_add_test_case noargs +}