Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lasombra/1888778 to your computer and use it in GitHub Desktop.
Save lasombra/1888778 to your computer and use it in GitHub Desktop.
_SC_NGROUPS_MAX cannot be used with getgrouplist on OS X
--- system.c.orig 2012-02-22 22:46:14.000000000 -0200
+++ system.c 2012-02-22 22:47:51.000000000 -0200
@@ -1161,7 +1161,14 @@
int groups_max(void)
{
-#if defined(SYSCONF_SC_NGROUPS_MAX)
+#if defined(DARWINOS)
+ /* On OS X, sysconf(_SC_NGROUPS_MAX) returns 16
+ * due to OS X's group nesting and getgrouplist
+ * will return a flat list; users can exceed the
+ * maximum of 16 groups. And easily will.
+ */
+ return 32; // NGROUPS_MAX is defined, hence the define above is void.
+#elif defined(SYSCONF_SC_NGROUPS_MAX)
int ret = sysconf(_SC_NGROUPS_MAX);
return (ret == -1) ? NGROUPS_MAX : ret;
#else
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment