aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-09-13 12:51:10 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-09-13 12:51:10 +0000
commit4f3209b9d4b24ebe9b76e3bfe8ddd87af5228af9 (patch)
treed6158492612846aecbdae95160d6e4ae51166622 /coreutils
parent0ee1cb00849355126eb59e8f3fccb02b4db2f5ed (diff)
downloadbusybox-w32-4f3209b9d4b24ebe9b76e3bfe8ddd87af5228af9.tar.gz
busybox-w32-4f3209b9d4b24ebe9b76e3bfe8ddd87af5228af9.tar.bz2
busybox-w32-4f3209b9d4b24ebe9b76e3bfe8ddd87af5228af9.zip
id: code shrink
function old new delta id_main 494 462 -32
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/id.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/coreutils/id.c b/coreutils/id.c
index b2f3b20e1..cf642c209 100644
--- a/coreutils/id.c
+++ b/coreutils/id.c
@@ -45,7 +45,7 @@ int id_main(int argc UNUSED_PARAM, char **argv)
45 uid_t uid; 45 uid_t uid;
46 gid_t gid; 46 gid_t gid;
47 gid_t *groups; 47 gid_t *groups;
48 int grp; 48 int n;
49 unsigned long flags; 49 unsigned long flags;
50 short status; 50 short status;
51#if ENABLE_SELINUX 51#if ENABLE_SELINUX
@@ -72,17 +72,17 @@ int id_main(int argc UNUSED_PARAM, char **argv)
72 /* in this case PRINT_REAL is the same */ 72 /* in this case PRINT_REAL is the same */
73 } 73 }
74 74
75 grp = getgroups(0, 0); 75 n = getgroups(0, NULL);
76 groups = (gid_t *)xmalloc(sizeof(gid_t) * grp); 76 groups = xmalloc(sizeof(groups[0]) * n);
77 getgroups(grp, (gid_t *)groups); 77 getgroups(n, groups);
78 78
79 if (flags & (JUST_ALL_GROUPS)) { 79 if (flags & JUST_ALL_GROUPS) {
80 while (grp--) { 80 while (n--) {
81 if (flags & NAME_NOT_NUMBER) 81 if (flags & NAME_NOT_NUMBER)
82 printf("%s", bb_getgrgid(NULL, 0, *groups++)); 82 printf("%s", bb_getgrgid(NULL, 0, *groups++));
83 else 83 else
84 printf("%d", *groups++); 84 printf("%d", (int) *groups++);
85 bb_putchar((grp > 0) ? ' ' : '\n'); 85 bb_putchar((n > 0) ? ' ' : '\n');
86 } 86 }
87 /* exit */ 87 /* exit */
88 fflush_stdout_and_exit(EXIT_SUCCESS); 88 fflush_stdout_and_exit(EXIT_SUCCESS);
@@ -105,7 +105,7 @@ int id_main(int argc UNUSED_PARAM, char **argv)
105#if ENABLE_SELINUX 105#if ENABLE_SELINUX
106 if (flags & JUST_CONTEXT) { 106 if (flags & JUST_CONTEXT) {
107 selinux_or_die(); 107 selinux_or_die();
108 if (argc - optind == 1) { 108 if (argv[optind]) {
109 bb_error_msg_and_die("user name can't be passed with -Z"); 109 bb_error_msg_and_die("user name can't be passed with -Z");
110 } 110 }
111 111
@@ -122,16 +122,17 @@ int id_main(int argc UNUSED_PARAM, char **argv)
122 /* Print full info like GNU id */ 122 /* Print full info like GNU id */
123 /* bb_getpwuid(0) doesn't exit on failure (returns NULL) */ 123 /* bb_getpwuid(0) doesn't exit on failure (returns NULL) */
124 status = printf_full(uid, bb_getpwuid(NULL, 0, uid), "uid="); 124 status = printf_full(uid, bb_getpwuid(NULL, 0, uid), "uid=");
125 bb_putchar(' '); 125 status |= printf_full(gid, bb_getgrgid(NULL, 0, gid), " gid=");
126 status |= printf_full(gid, bb_getgrgid(NULL, 0, gid), "gid="); 126 {
127 printf(" groups="); 127 const char *msg = " groups=";
128 while (grp--) { 128 while (n--) {
129 status |= printf_full(*groups, bb_getgrgid(NULL, 0, *groups), ""); 129 status |= printf_full(*groups, bb_getgrgid(NULL, 0, *groups), msg);
130 if (grp > 0) 130 msg = ",";
131 bb_putchar(','); 131 groups++;
132 groups++; 132 }
133 } 133 }
134 /* Don't free groups */ 134 /* we leak groups vector... */
135
135#if ENABLE_SELINUX 136#if ENABLE_SELINUX
136 if (is_selinux_enabled()) { 137 if (is_selinux_enabled()) {
137 security_context_t mysid; 138 security_context_t mysid;