logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 57f8ff618f6c3d40d18daed16da4e739c3214661
parent 96e9072e6f8b9c253f06590d4efd18f458a47c05
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 22 Apr 2022 08:48:26 +0200

bin/link: New util

Diffstat:

Abin/link.128++++++++++++++++++++++++++++
Abin/link.c25+++++++++++++++++++++++++
Mcoreutils.txt2+-
Mtest-bin/Kyuafile1+
Atest-bin/link32++++++++++++++++++++++++++++++++
5 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/bin/link.1 b/bin/link.1 @@ -0,0 +1,28 @@ +.\" 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 +.Dd 2022-04-22 +.Dt LINK 1 +.Os +.Sh NAME +.Nm link +.Nd call +.Xr link 3 +function +.Sh SYNOPSIS +.Nm +.Ar reference +.Ar destination +.Sh DESCRIPTION +.Nm +will call +.Xr link 3 +with +.Ar reference +and +.Ar destination , +returning an error message in case of failure. +.Sh EXIT STATUS +.Ex -std +.Sh AUTHORS +.An Haelwenn (lanodan) Monnier Aq Mt contact@hacktivis.me diff --git a/bin/link.c b/bin/link.c @@ -0,0 +1,25 @@ +// 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 + +#define _POSIX_C_SOURCE 200809L +#include <stdio.h> /* perror, fprintf */ +#include <unistd.h> /* link */ + +int +main(int argc, char *argv[]) +{ + if(argc != 3) + { + fprintf(stderr, "usage: link <reference> <destination>\n"); + return 1; + } + + if(link(argv[1], argv[2]) != 0) + { + perror("link"); + return 1; + } + + return 0; +} diff --git a/coreutils.txt b/coreutils.txt @@ -36,7 +36,7 @@ hostid: No, get a better id(ea) id: Done install: No? join: ? -link: Todo +link: Done ln: Todo logname: No, POSIX ls: ? diff --git a/test-bin/Kyuafile b/test-bin/Kyuafile @@ -17,6 +17,7 @@ atf_test_program{name="errno", required_files=basedir.."/bin/errno", timeout=1} atf_test_program{name="false", required_files=basedir.."/bin/false", timeout=1} atf_test_program{name="humanize", required_files=basedir.."/bin/humanize", timeout=1} atf_test_program{name="id", required_files=basedir.."/bin/id", timeout=1} +atf_test_program{name="link", required_files=basedir.."/bin/link", timeout=1} atf_test_program{name="lolcat", required_files=basedir.."/bin/lolcat", timeout=1} atf_test_program{name="mdate", required_files=basedir.."/bin/mdate", timeout=1} atf_test_program{name="pwd", required_files=basedir.."/bin/pwd", timeout=1} diff --git a/test-bin/link b/test-bin/link @@ -0,0 +1,32 @@ +#!/usr/bin/env atf-sh +atf_test_case empty +empty_body() { + atf_check -s exit:1 -e "inline:usage: link <reference> <destination>\n" ../bin/link +} + +atf_test_case basic cleanup +basic_body() { + touch foo + + atf_check ../bin/link foo bar + atf_check -o "inline:0 foo\n0 bar\n0 total\n" wc -c foo bar + + echo hello >> foo + atf_check -o "inline: 6 foo\n 6 bar\n12 total\n" wc -c foo bar +} +basic_cleanup() { + atf_check rm -f foo bar +} + +atf_test_case enoent +enoent_body() { + atf_check -s exit:1 -e 'inline:link: No such file or directory\n' ../bin/link /var/empty/e/no/ent enoent_foo + atf_check -s exit:1 -e 'inline:link: No such file or directory\n' ../bin/link enoent_bar /var/empty/e/no/ent +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case empty + atf_add_test_case basic + atf_add_test_case enoent +}