Another easy one. One of the context lines will have to be updated in Makefile to apply after the link(1) patch.
>From 99c822c371c0e51464b9093a66dd5c73e3fae8e2 Mon Sep 17 00:00:00 2001 From: Brandon Mulcahy <bran...@jangler.info> Date: Thu, 16 Oct 2014 17:15:16 -0400 Subject: [PATCH] Add logname(1)
--- Makefile | 1 + logname.1 | 8 ++++++++ logname.c | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 logname.1 create mode 100644 logname.c diff --git a/Makefile b/Makefile index 6f995be..2f0ba53 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,7 @@ SRC = \ head.c \ hostname.c \ kill.c \ + logname.c \ ln.c \ ls.c \ md5sum.c \ diff --git a/logname.1 b/logname.1 new file mode 100644 index 0000000..0eebacf --- /dev/null +++ b/logname.1 @@ -0,0 +1,8 @@ +.TH LOGNAME 1 sbase\-VERSION +.SH NAME +logname \- return the user's login name +.SH SYNOPSIS +.B logname +.SH DESCRIPTION +.B logname +prints the login name of the current user. diff --git a/logname.c b/logname.c new file mode 100644 index 0000000..aa6357f --- /dev/null +++ b/logname.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <unistd.h> +#include "util.h" + +int +main(int argc, char *argv[]) +{ + char *login; + + if (argc != 1) + eprintf("usage: %s\n", argv[0]); + + if ((login = getlogin())) + printf("%s\n", login); + else + /* perror would say "No such file or directory" */ + eprintf("%s: no login name\n", argv[0]); + + return 0; +} -- 2.1.2