xref: /titanic_51/usr/src/lib/libast/common/comp/getgroups.c (revision 16dd44c265271a75647fb0bb41109bb7c585a526)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 
24 #include <ast.h>
25 
26 #if !defined(getgroups) && defined(_lib_getgroups)
27 
28 NoN(getgroups)
29 
30 #else
31 
32 #include <error.h>
33 
34 #if defined(getgroups)
35 #undef	getgroups
36 #define	ast_getgroups	_ast_getgroups
37 #define botched		1
38 extern int		getgroups(int, int*);
39 #else
40 #define ast_getgroups	getgroups
41 #endif
42 
43 #if defined(__EXPORT__)
44 #define extern	__EXPORT__
45 #endif
46 
47 extern int
48 ast_getgroups(int len, gid_t* set)
49 {
50 #if botched
51 #if NGROUPS_MAX < 1
52 #undef	NGROUPS_MAX
53 #define NGROUPS_MAX	1
54 #endif
55 	register int	i;
56 	int		big[NGROUPS_MAX];
57 #else
58 #undef	NGROUPS_MAX
59 #define NGROUPS_MAX	1
60 #endif
61 	if (!len) return(NGROUPS_MAX);
62 	if (len < 0 || !set)
63 	{
64 		errno = EINVAL;
65 		return(-1);
66 	}
67 #if botched
68 	len = getgroups(len > NGROUPS_MAX ? NGROUPS_MAX : len, big);
69 	for (i = 0; i < len; i++)
70 		set[i] = big[i];
71 	return(len);
72 #else
73 	*set = getgid();
74 	return(1);
75 #endif
76 }
77 
78 #endif
79