-/* $OpenBSD: id.c,v 1.20 2013/09/06 19:48:46 okan Exp $ */
+/* $OpenBSD: id.c,v 1.21 2014/07/14 05:41:00 guenther Exp $ */
/*-
* Copyright (c) 1991, 1993
int cnt, ngroups;
uid_t uid, euid;
gid_t groups[NGROUPS], gid, egid, lastgid;
- char *fmt;
+ char *prefix;
uid = getuid();
(void)printf("uid=%u", uid);
(void)printf("(%s)", gr->gr_name);
}
if ((ngroups = getgroups(NGROUPS, groups))) {
- for (fmt = " groups=%u", lastgid = (gid_t)-1, cnt = 0;
- cnt < ngroups; fmt = ", %u", lastgid = gid) {
+ for (prefix = " groups=", lastgid = (gid_t)-1, cnt = 0;
+ cnt < ngroups; prefix = ", ", lastgid = gid) {
gid = groups[cnt++];
if (lastgid == gid)
continue;
- (void)printf(fmt, gid);
+ (void)printf("%s%u", prefix, gid);
if ((gr = getgrgid(gid)))
(void)printf("(%s)", gr->gr_name);
}
int cnt, ngroups;
uid_t uid;
struct group *gr;
- char *fmt;
+ char *prefix;
uid = pw->pw_uid;
(void)printf("uid=%u(%s)", uid, pw->pw_name);
(void)printf("(%s)", gr->gr_name);
ngroups = NGROUPS + 1;
(void) getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups);
- fmt = " groups=%u";
+ prefix = " groups=";
for (cnt = 0; cnt < ngroups;) {
gid = groups[cnt];
- (void)printf(fmt, gid);
- fmt = ", %u";
+ (void)printf("%s%u", prefix, gid);
+ prefix = ", ";
if ((gr = getgrgid(gid)))
(void)printf("(%s)", gr->gr_name);
/* Skip same gid entries. */
int cnt, ngroups;
gid_t gid, groups[NGROUPS + 1];
struct group *gr;
- char *fmt;
+ char *prefix;
if (pw) {
ngroups = NGROUPS + 1;
groups[0] = getgid();
ngroups = getgroups(NGROUPS, groups + 1) + 1;
}
- fmt = nflag ? "%s" : "%u";
+ prefix = "";
for (cnt = 0; cnt < ngroups;) {
gid = groups[cnt];
if (nflag) {
if ((gr = getgrgid(gid)))
- (void)printf(fmt, gr->gr_name);
+ (void)printf("%s%s", prefix, gr->gr_name);
else
- (void)printf(*fmt == ' ' ? " %u" : "%u",
- gid);
- fmt = " %s";
+ (void)printf("%s%u", prefix, gid);
} else {
- (void)printf(fmt, gid);
- fmt = " %u";
+ (void)printf("%s%u", prefix, gid);
}
+ prefix = " ";
/* Skip same gid entries. */
while (++cnt < ngroups && gid == groups[cnt]);
}