From 3da7411f0a5433aa866d5421a7e799b66fc7ac58 Mon Sep 17 00:00:00 2001 From: s-p-k Date: Fri, 18 Oct 2013 16:51:44 +0300 Subject: [PATCH] Add logname(1) --- Makefile | 1 + TODO | 2 -- logname.1 | 9 +++++++++ logname.c | 27 +++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 logname.1 create mode 100644 logname.c diff --git a/Makefile b/Makefile index 326cae8..f431b87 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,7 @@ SRC = \ id.c \ kill.c \ ln.c \ + logname.c \ ls.c \ mc.c \ md5sum.c \ diff --git a/TODO b/TODO index 3f7dc12..ef85d9a 100644 --- a/TODO +++ b/TODO @@ -14,8 +14,6 @@ unexpand [-a] [-t N] [file...] od/hd -logname - uuencode uudecode diff --git a/logname.1 b/logname.1 new file mode 100644 index 0000000..6785e92 --- /dev/null +++ b/logname.1 @@ -0,0 +1,9 @@ +.TH LOGNAME 1 sbase\-VERSION +.SH NAME +logname \- print user's login name. +.SH SYNOPSIS +.B logname +.SH DESCRIPTION +.B +The logname utility writes the user's login name to standard output +followed by a newline. diff --git a/logname.c b/logname.c new file mode 100644 index 0000000..b621a9f --- /dev/null +++ b/logname.c @@ -0,0 +1,27 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include "util.h" + +static void +usage(void) +{ + eprintf("usage: %s\n", argv0); +} + +int +main(int argc, char *argv[]) +{ + char *p; + + ARGBEGIN { + default: + usage(); + } ARGEND; + + p = getenv("LOGNAME"); + if (!p) + enprintf(EXIT_FAILURE, "no login name\n"); + puts(p); + return EXIT_SUCCESS; +} -- 1.8.4.1