logo

utils-std

Collection of commonly available Unix tools
commit: 9923552690ca482655f69012a9de7c28c4e9545d
parent e29d36fff18b6016373a94c47fd72066096aa82f
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed, 27 Mar 2024 03:53:38 +0100

cmd/logname: new

Diffstat:

Acmd/logname.128++++++++++++++++++++++++++++
Acmd/logname.c26++++++++++++++++++++++++++
Mcoreutils.txt2+-
Mlsb_commands.txt2+-
Mposix_utilities.txt2+-
Atest-cmd/logname.t9+++++++++
6 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/cmd/logname.1 b/cmd/logname.1 @@ -0,0 +1,28 @@ +.\" 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-03-27 +.Dt LOGNAME 1 +.Os +.Sh NAME +.Nm logname +.Nd print user's login name +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +.Nm +prints the user's login name. +Should be equivalent to +.Cm id +.Fl un . +.Sh EXIT STATUS +.Ex -std +.Sh SEE ALSO +.Xr getlogin 3 +.Sh STANDARDS +.Nm +should be compliant with the +.St -p1003.1-2008 +specification. +.Sh AUTHORS +.An Haelwenn (lanodan) Monnier Aq Mt contact+utils@hacktivis.me diff --git a/cmd/logname.c b/cmd/logname.c @@ -0,0 +1,26 @@ +// 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 <stdio.h> // puts, perror +#include <unistd.h> // getlogin + +int +main(void) +{ + char *name = getlogin(); + if(name == NULL) + { + perror("logname: getlogin"); + return 1; + } + + if(puts(name) < 0) + { + perror("puts"); + return 1; + } + + return 0; +} diff --git a/coreutils.txt b/coreutils.txt @@ -40,7 +40,7 @@ install: No join: ? link: Done ln: Todo -logname: No, POSIX +logname: Done ls: ? md5sum: No mkdir: Todo diff --git a/lsb_commands.txt b/lsb_commands.txt @@ -67,7 +67,7 @@ ln: Todo locale: No localedef: No logger: Maybe -logname: No, POSIX +logname: Done lp: No lpr: No ls: ? diff --git a/posix_utilities.txt b/posix_utilities.txt @@ -69,7 +69,7 @@ ln locale localedef logger -logname +logname: Done lp: no ls m4: no diff --git a/test-cmd/logname.t b/test-cmd/logname.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 logname)" = "$TESTDIR/../cmd/logname" + + $ test "$(id -un)" = "$(logname)"