From 5f97c77a276414eb0aa473ef6ddf0d4cc89531af Mon Sep 17 00:00:00 2001 From: Alan Potteiger Date: Wed, 23 Nov 2022 00:18:18 +0100 Subject: [PATCH] `logname` --- Makefile | 2 +- README | 1 + logname.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 logname.c diff --git a/Makefile b/Makefile index 9f6ce45..61ac29f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -BIN=cat pwd sleep tty +BIN=cat logname pwd sleep tty CFLAGS=-std=c99 all: $(BIN) clean: diff --git a/README b/README index 05966b6..497ed4f 100644 --- a/README +++ b/README @@ -11,6 +11,7 @@ Utilities --------- - cat +- logname - pwd - sleep - tty diff --git a/logname.c b/logname.c new file mode 100644 index 0000000..ac9c252 --- /dev/null +++ b/logname.c @@ -0,0 +1,28 @@ +/* `logname.c` - return the user's login name + Copyright (c) 2022, Alan Potteiger + See `LICENSE` for copyright and license details */ + +#define _POSIX_C_SOURCE 200809L + +#include +#include + +static const char *usage = { + "usage: logname\n" +}; + +int +main(int argc, char *argv[]) +{ + char *name; + + name = getlogin(); + if (name == NULL) { + fputs("logname: login name not set\n", stderr); + return 1; + } + + puts(name); + return 0; +} + -- 2.11.4.GIT