getgrouplist(3) vs. getgroups(3)

Roland Illig roland.illig at gmx.de
Fri Jul 22 13:16:47 UTC 2005


Roland Illig wrote:
> +    if (!initialized) {
> +	uid = getuid ();
> +	ngroups = getgroups (0, NULL);
> +	if (ngroups != -1) {
             /* allocate space for one more element
              * than will be filled by getgroups(). */
> +	    groups = g_new (gid_t, ngroups + 1);
> +	    ngroups = getgroups (ngroups, groups);
> +
> +	    /* getgroups() may or may not return the effective group ID,
> +	     * so we always include it at the end of the list. */
> +	    if (ngroups >= 0) {
> +		groups[ngroups++] = getegid();
> +	    }
> +	}
> +	initialized = TRUE;
> +    }

I felt the need for that comment because otherwise the "+ 1" could 
become misinterpreted. Together with the second comment, it should be ok.

Roland



More information about the mc-devel mailing list