getgrouplist(3) vs. getgroups(3)

Roland Illig roland.illig at gmx.de
Fri Jul 22 08:52:20 UTC 2005


Jakub Jelinek wrote:
> But, IMHO far better would be to:
> static gid_t *groups;
> if (!groups) {
>   uid = getuid ();
>   n = getgroups (0, NULL);
>   if (n < 0) error_handling;
>   groups = malloc (n * sizeof (gid_t));
>   if (groups == NULL) error_handling;
>   n = getgroups (n, groups);
>   if (n < 0) error_handling;
> }

That sounds great. I think error_handling should be to just return 2 in 
this case.

> and perhaps if n is big enough qsort groups array and use
> a binary search instead of linear one.

Are there systems where there are users that are in more than 20 groups?

(Just wondering. ;))

Roland



More information about the mc-devel mailing list