summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-10-16 08:23:41 +0000
committerJim Meyering <jim@meyering.net>2003-10-16 08:23:41 +0000
commit5b18a21b2db5304e2a13e5805471dd92f6effbdc (patch)
tree419c7dc2af3f27f7aedfa3ff20d9b05d94a6a41b /lib
parent5ee14fea3f01ad45ab2964eb7c6ea50ab22429c5 (diff)
downloadcoreutils-5b18a21b2db5304e2a13e5805471dd92f6effbdc.tar.xz
Include <errno.h>, <stdlib.h>.
(getgroups): First arg is int, not size_t. Don't let 'free' mangle errno.
Diffstat (limited to 'lib')
-rw-r--r--lib/getgroups.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/getgroups.c b/lib/getgroups.c
index f6808b333..e27cadc3e 100644
--- a/lib/getgroups.c
+++ b/lib/getgroups.c
@@ -20,6 +20,8 @@
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
+#include <errno.h>
+#include <stdlib.h>
#include "xalloc.h"
@@ -29,10 +31,11 @@
provided function handle all others. */
int
-getgroups (size_t n, GETGROUPS_T *group)
+getgroups (int n, GETGROUPS_T *group)
{
int n_groups;
GETGROUPS_T *gbuf;
+ int saved_errno;
#undef getgroups
@@ -43,6 +46,9 @@ getgroups (size_t n, GETGROUPS_T *group)
gbuf = NULL;
while (1)
{
+ /* No need to worry about address arithmetic overflow here,
+ since the ancient systems that we're running on have low
+ limits on the number of secondary groups. */
gbuf = xrealloc (gbuf, n * sizeof (GETGROUPS_T));
n_groups = getgroups (n, gbuf);
if (n_groups < n)
@@ -50,7 +56,9 @@ getgroups (size_t n, GETGROUPS_T *group)
n += 10;
}
+ saved_errno = errno;
free (gbuf);
+ errno = saved_errno;
return n_groups;
}