annotate toys/whoami.c @ 521:b64064a044a4

Minor optimization.
author Rob Landley <rob@landley.net>
date Sun, 04 Mar 2012 01:29:57 -0600
parents 3ee4c79971e9
children 2247cdb73f2d
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
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 }