~sircmpwn/ctools

bc6c5b9b6462bdd7e2ef720445973e6f2078d959 — Adrian Perez de Castro 1 year, 4 months ago 35f7a1b
Implement logname

Implementation of the getlogin(3) function tend to be terrible in
C libraries, but the POSIX standard requires that logname uses it.
3 files changed, 32 insertions(+), 1 deletions(-)

M STATUS
M meson.build
A src/logname.c
M STATUS => STATUS +1 -1
@@ 75,7 75,7 @@ T       ln
T       locale
T       localedef
T       logger
T       logname
  D     logname
    W   lp
T       ls
T       m4

M meson.build => meson.build +1 -0
@@ 19,6 19,7 @@ oneshots = [
	'cksum',
	'cmp',
	'false',
	'logname',
	'nice',
	'true',
	'tty',

A src/logname.c => src/logname.c +30 -0
@@ 0,0 1,30 @@
#include <stdio.h>
#include <unistd.h>

static void
usage(void)
{
	fprintf(stderr, "usage: logname\n");
}

int
main(int argc, char *argv[])
{
	while (getopt(argc, argv, "") != -1) {
		usage();
		return 1;
	}

	if (argc != optind) {
		usage();
		return 1;
	}

	char *name = getlogin();
	if (!name) {
		perror("getlogin");
		return 1;
	}
	printf("%s\n", name);
	return 0;
}