simplified uid() and fixed username()
This commit is contained in:
parent
825141633b
commit
2f8335abf0
1 changed files with 6 additions and 25 deletions
31
slstatus.c
31
slstatus.c
|
@ -474,40 +474,21 @@ uptime(void)
|
||||||
static char *
|
static char *
|
||||||
username(void)
|
username(void)
|
||||||
{
|
{
|
||||||
/* FIXME: WHY USE REGISTER MODIFIER? */
|
uid_t uid = geteuid();
|
||||||
register struct passwd *pw;
|
struct passwd *pw = getpwuid(uid);
|
||||||
register uid_t uid;
|
|
||||||
|
|
||||||
uid = geteuid();
|
if (pw == NULL)
|
||||||
pw = getpwuid(uid);
|
|
||||||
|
|
||||||
if (pw)
|
|
||||||
return smprintf("%s", pw->pw_name);
|
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);
|
return smprintf(UNKNOWN_STR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
uid(void)
|
uid(void)
|
||||||
{
|
{
|
||||||
/* FIXME: WHY USE register modifier? */
|
return smprintf("%d", geteuid());
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue