comparison toys/whoami.c @ 520:3ee4c79971e9

Add whoami.
author Georgi Chorbadzhiyski <gf@unixsol.org>
date Sun, 04 Mar 2012 01:26:48 -0600
parents
children b64064a044a4
comparison
equal deleted inserted replaced
519:c6b3bd689d0a 520:3ee4c79971e9
1 /* vi: set sw=4 ts=4:
2 *
3 * whoami.c - Print effective user id
4 *
5 * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org>
6 *
7
8 USE_WHOAMI(NEWTOY(whoami, NULL, TOYFLAG_USR|TOYFLAG_BIN))
9
10 config WHOAMI
11 bool "whoami"
12 default y
13 help
14 usage: whoami
15
16 Print effective user id.
17 */
18
19 #include "toys.h"
20
21 void whoami_main(void)
22 {
23 struct passwd *pw = getpwuid(geteuid());
24
25 if (!pw) {
26 perror("getpwuid");
27 toys.exitval = 1;
28 return;
29 }
30
31 xprintf("%s\n", pw->pw_name);
32 }