- pwent = getpwuid (uid);
- tail = xmalloc (sizeof (struct userid));
- tail->id.u = uid;
- tail->name = pwent ? xstrdup (pwent->pw_name) : NULL;
+ if (match == NULL)
+ {
+ struct passwd *pwent = getpwuid (uid);
+ char const *name = pwent ? pwent->pw_name : "";
+ match = xmalloc (offsetof (struct userid, name) + strlen (name) + 1);
+ match->id.u = uid;
+ strcpy (match->name, name);
+
+ /* Add to the head of the list, so most recently used is first. */
+ match->next = user_alist;
+ user_alist = match;
+ }