annotate toys/whoami.c @ 528:878b94b32866

Comment and whitespace tweaks.
author Rob Landley <rob@landley.net>
date Tue, 06 Mar 2012 20:48:27 -0600
parents 2247cdb73f2d
children
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 *
524
2247cdb73f2d whoami: fix toy description, no code changes
Pere Orga <gotrunks@gmail.com>
parents: 521
diff changeset
3 * whoami.c - Print effective user name
520
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
528
878b94b32866 Comment and whitespace tweaks.
Rob Landley <rob@landley.net>
parents: 524
diff changeset
16 Print effective user name.
520
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
521
b64064a044a4 Minor optimization.
Rob Landley <rob@landley.net>
parents: 520
diff changeset
31 xputs(pw->pw_name);
520
3ee4c79971e9 Add whoami.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
32 }