Re: getgrouplist(3) vs. getgroups(3)



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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]