summaryrefslogtreecommitdiff
path: root/slstatus.c
diff options
context:
space:
mode:
authorAli H. Fardan <raiz@firemail.cc>2016-09-01 21:35:32 +0300
committerAli H. Fardan <raiz@firemail.cc>2016-09-01 21:35:32 +0300
commit2f8335abf0d6347100cf63d82e8151ad0ff97ab0 (patch)
tree42d513346a1242b7e03d1226746ed3bcb28e0615 /slstatus.c
parent825141633bad2264c67c38ebcaab63f4c96631d3 (diff)
simplified uid() and fixed username()
Diffstat (limited to 'slstatus.c')
-rw-r--r--slstatus.c31
1 files changed, 6 insertions, 25 deletions
diff --git a/slstatus.c b/slstatus.c
index d360977..7337e4a 100644
--- a/slstatus.c
+++ b/slstatus.c
@@ -474,40 +474,21 @@ uptime(void)
static char *
username(void)
{
- /* FIXME: WHY USE REGISTER MODIFIER? */
- register struct passwd *pw;
- register uid_t uid;
+ uid_t uid = geteuid();
+ struct passwd *pw = getpwuid(uid);
- uid = geteuid();
- pw = getpwuid(uid);
-
- if (pw)
+ if (pw == NULL)
return smprintf("%s", pw->pw_name);
- else {
- fprintf(stderr, "Could not get username: %s\n",
- strerror(errno));
- return smprintf(UNKNOWN_STR);
- }
+ fprintf(stderr, "Could not get username: %s\n",
+ strerror(errno));
return smprintf(UNKNOWN_STR);
}
static char *
uid(void)
{
- /* FIXME: WHY USE register modifier? */
- register uid_t uid;
-
- uid = geteuid();
-
- if (uid)
- return smprintf("%d", uid);
- else {
- fprintf(stderr, "Could not get uid.\n");
- return smprintf(UNKNOWN_STR);
- }
-
- return smprintf(UNKNOWN_STR);
+ return smprintf("%d", geteuid());
}