annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
520
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
2 *
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
3 * whoami.c - Print effective user id
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
4 *
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
5 * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org>
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
6 *
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
7
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
8 USE_WHOAMI(NEWTOY(whoami, NULL, TOYFLAG_USR|TOYFLAG_BIN))
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
9
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
10 config WHOAMI
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
11 bool "whoami"
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
12 default y
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
13 help
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
14 usage: whoami
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
15
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
16 Print effective user id.
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
17 */
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
18
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
19 #include "toys.h"
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
20
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
21 void whoami_main(void)
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
22 {
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
23 struct passwd *pw = getpwuid(geteuid());
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
24
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
25 if (!pw) {
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
26 perror("getpwuid");
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
27 toys.exitval = 1;
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
28 return;
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
29 }
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
30
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
31 xprintf("%s\n", pw->pw_name);
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
32 }