ref: 7465ef2dfc96bcfdd74df3fedbebca033c928cc9
parent: 3943794e421f09cb4789173935dd066d615b676c
author: mkf <mkf@cloud9p.org>
date: Thu Dec 7 13:02:44 EST 2023
id: use new APIs
--- a/cmd/id.c
+++ b/cmd/id.c
@@ -13,34 +13,20 @@
int
id_main(int argc, char **argv)
{
- char *tmp;
- ll_t *t;
- user_t *u;
+ int uid;
+ user_t u;
if(argc != 2)
return usage();
- tmp = malloc(2 << 8);
- u = nil;
- t = users;
- while(t != nil)
- {
- u = (user_t*)t->val;
- /* i wanted to add a iflag, but let it do both for now */
- if(!strcmp(u->name, argv[1]) || !strcmp(itoa(u->id, tmp, 10), argv[1]))
- break;
- u = nil;
- t = (ll_t*)t->next;
- }
+ uid = getuser(argv[1]);
- free(tmp);
-
- if(u == nil)
+ if(uid < 0)
{
printf("No such user or id\n");
return NO_SUCH_USER;
}
- printf("username: %s\n", u->name);
- printf("id: %d\n", u->id);
+ printf("username: %s\n", argv[1]);
+ printf("id: %d\n", uid);
return OK;
}