logo

utils-std

Collection of commonly available Unix tools
commit: b6d5e3388916b2f608a91a94965cecab7d5886b2
parent 83a9997e35618e884044c769960a794986990cf3
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 11 Apr 2024 20:03:42 +0200

cmd/arch: new

Diffstat:

Acmd/arch.125+++++++++++++++++++++++++
Acmd/arch.c29+++++++++++++++++++++++++++++
Mcoreutils.txt2+-
Atest-cmd/arch.t9+++++++++
4 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/cmd/arch.1 b/cmd/arch.1 @@ -0,0 +1,25 @@ +.\" utils-std: Collection of commonly available Unix tools +.\" Copyright 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +.\" SPDX-License-Identifier: MPL-2.0 +.Dd 2024-04-11 +.Dt ARCH 1 +.Os +.Sh NAME +.Nm arch +.Nd print architecture name (same as uname -m) +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +.Nm +prints the architecture name, aka machine name. +Should be equivalent to +.Cm uname +.Fl m . +.Sh EXIT STATUS +.Ex -std +.Sh SEE ALSO +.Xr uname 1 +.Sh STANDARDS +GNU extension. +.Sh AUTHORS +.An Haelwenn (lanodan) Monnier Aq Mt contact+utils@hacktivis.me diff --git a/cmd/arch.c b/cmd/arch.c @@ -0,0 +1,29 @@ +// utils-std: Collection of commonly available Unix tools +// SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +// SPDX-License-Identifier: MPL-2.0 + +#define _POSIX_C_SOURCE 200809L + +#include <errno.h> +#include <stdio.h> // fprintf +#include <string.h> // strerror +#include <sys/utsname.h> // uname + +int +main() +{ + struct utsname name; + if(uname(&name) < 0) + { + fprintf(stderr, "arch: Failed to get system name: %s\n", strerror(errno)); + return 1; + } + + if(puts(name.machine) < 0) + { + fprintf(stderr, "arch: Failed to write machine architecture: %s\n", strerror(errno)); + return 1; + } + + return 0; +} diff --git a/coreutils.txt b/coreutils.txt @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> # SPDX-License-Identifier: MPL-2.0 [: ?, see test -arch: No +arch: Done b2sum: No base32: No base64: Done diff --git a/test-cmd/arch.t b/test-cmd/arch.t @@ -0,0 +1,9 @@ +#!/usr/bin/env cram +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + + $ export PATH="$TESTDIR/../cmd:$PATH" + + $ test "$(command -v rm)" = "$TESTDIR/../cmd/rm" + + $ test "$(arch)" = "$(uname -m)"