~sircmpwn/ctools

ref: bb5007143abfc22d947c422bfade941e2a741c8c ctools/src/logname.c -rw-r--r-- 372 bytes
bb500714Drew DeVault link: add conformance test 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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;
}