Ondrej Vasik 0363d6
diff -urp coreutils-6.10-orig/lib/getugroups.c coreutils-6.10/lib/getugroups.c
Ondrej Vasik 0363d6
--- coreutils-6.10-orig/lib/getugroups.c	2007-10-17 15:47:25.000000000 +0200
Ondrej Vasik 0363d6
+++ coreutils-6.10/lib/getugroups.c	2008-01-24 16:37:04.000000000 +0100
Ondrej Vasik 0363d6
@@ -19,6 +19,9 @@
Tim Waugh d66c4d
 
Tim Waugh d66c4d
 #include <config.h>
Tim Waugh 0b3fe5
 
Tim Waugh 0b3fe5
+/* We do not need this code if getgrouplist(3) is available.  */
Tim Waugh 0b3fe5
+#ifndef HAVE_GETGROUPLIST
Tim Waugh 0b3fe5
+
Ondrej Vasik 0363d6
 #include "getugroups.h"
Ondrej Vasik 0363d6
 
Tim Waugh 0b3fe5
 #include <stdio.h> /* grp.h on alpha OSF1 V2.0 uses "FILE *". */
Ondrej Vasik 0363d6
@@ -114,3 +117,4 @@ getugroups (int maxcount, GETGROUPS_T *g
Tim Waugh 0b3fe5
 
Tim Waugh 0b3fe5
   return count;
Tim Waugh 0b3fe5
 }
Tim Waugh 0b3fe5
+#endif	/* have getgrouplist */
Ondrej Vasik 0363d6
diff -urp coreutils-6.10-orig/lib/mgetgroups.c coreutils-6.10/lib/mgetgroups.c
Ondrej Vasik 0363d6
--- coreutils-6.10-orig/lib/mgetgroups.c	2007-11-25 14:23:31.000000000 +0100
Ondrej Vasik 0363d6
+++ coreutils-6.10/lib/mgetgroups.c	2008-01-24 16:41:15.000000000 +0100
Ondrej Vasik 0363d6
@@ -43,9 +43,17 @@ mgetgroups (const char *username, gid_t 
Ondrej Vasik 0363d6
   int ng;
Ondrej Vasik 0363d6
   GETGROUPS_T *g;
Ondrej Vasik 0363d6
 
Ondrej Vasik 0363d6
-  max_n_groups = (username
Ondrej Vasik 0363d6
-		  ? getugroups (0, NULL, username, gid)
Ondrej Vasik 0363d6
-		  : getgroups (0, NULL));
Ondrej Vasik 0363d6
+    if (!username)
Ondrej Vasik 0363d6
+      max_n_groups = getgroups(0, NULL);
Ondrej Vasik 0363d6
+  else 
Ondrej Vasik 0363d6
+   {
Tim Waugh 0b3fe5
+#ifdef HAVE_GETGROUPLIST
Tim Waugh 0b3fe5
+      max_n_groups = 0;
Tim Waugh 0b3fe5
+      getgrouplist (username, gid, NULL, &max_n_groups);
Tim Waugh 0b3fe5
+#else
Tim Waugh 0b3fe5
+      max_n_groups = getugroups (0, NULL, username, gid);
Tim Waugh 0b3fe5
+#endif
Ondrej Vasik 0363d6
+   }
Tim Waugh 0b3fe5
 
Ondrej Vasik 0363d6
   /* If we failed to count groups with NULL for a buffer,
Ondrej Vasik 0363d6
      try again with a non-NULL one, just in case.  */
Ondrej Vasik 0363d6
@@ -62,9 +70,25 @@ mgetgroups (const char *username, gid_t 
Ondrej Vasik 0363d6
   if (g == NULL)
Ondrej Vasik 0363d6
     return -1;
Ondrej Vasik 0363d6
 
Ondrej Vasik 0363d6
-  ng = (username
Ondrej Vasik 0363d6
-	? getugroups (max_n_groups, g, username, gid)
Ondrej Vasik 0363d6
-	: getgroups (max_n_groups, g));
Ondrej Vasik 0363d6
+  if (!username)
Ondrej Vasik 0363d6
+    ng = getgroups (max_n_groups, g);
Ondrej Vasik 0363d6
+  else
Ondrej Vasik 0363d6
+    {
Tim Waugh c3e4c8
+#ifdef HAVE_GETGROUPLIST
Tim Waugh c3e4c8
+	  int e;
Tim Waugh c3e4c8
+	  ng = max_n_groups;
Tim Waugh c3e4c8
+	  while ((e = getgrouplist (username, gid, g, &ng)) == -1
Tim Waugh c3e4c8
+		 && ng > max_n_groups)
Tim Waugh c3e4c8
+	    {
Tim Waugh c3e4c8
+	      max_n_groups = ng;
Tim Waugh c3e4c8
+	      g = xrealloc (g, max_n_groups * sizeof (GETGROUPS_T));
Tim Waugh c3e4c8
+	    }
Tim Waugh c3e4c8
+	  if (e == -1)
Tim Waugh c3e4c8
+	    ng = -1;
Tim Waugh 0b3fe5
+#else
Tim Waugh c3e4c8
+	  ng = getugroups (max_n_groups, g, username, gid);
Tim Waugh 0b3fe5
+#endif
Ondrej Vasik 0363d6
+    }
Tim Waugh 0b3fe5
 
Tim Waugh 0b3fe5
   if (ng < 0)
Ondrej Vasik 0363d6
     {
Ondrej Vasik 0363d6
diff -urp coreutils-6.10-orig/m4/jm-macros.m4 coreutils-6.10/m4/jm-macros.m4
Ondrej Vasik 0363d6
--- coreutils-6.10-orig/m4/jm-macros.m4	2007-11-25 14:23:31.000000000 +0100
Ondrej Vasik 0363d6
+++ coreutils-6.10/m4/jm-macros.m4	2008-01-24 16:42:00.000000000 +0100
Ondrej Vasik 0363d6
@@ -52,6 +52,7 @@ AC_DEFUN([coreutils_MACROS],
Tim Waugh d66c4d
     fchown \
Tim Waugh d66c4d
     fchmod \
Tim Waugh d66c4d
     ftruncate \
Tim Waugh d66c4d
+    getgrouplist \
Tim Waugh d66c4d
     iswspace \
Tim Waugh d66c4d
     mkfifo \
Tim Waugh d66c4d
     mbrlen \