/*
*      SCCS:   @(#)install/userintf/base_setgrps	Rel 4.4.1 (06/09/97)
*
*	UniSoft Ltd., London, England
*/
/***********************************************************************

NAME:		base_setgrps - user-modifiable setgrps() routine
PROJECT:	VSX (X/OPEN Validation Suite)
AUTHOR:		Geoff Clare, UniSoft Ltd.
DATE CREATED:	December 1996
MODIFICATIONS:

************************************************************************/

/*
 *	Setgrps() sets the current groups list to the group id's in
 *	"grparray".  This array should contain "ngrps" entries.
 *	Setgrps() is only called after setprv(PRV_SETGRPS) since setting
 *	groups is usually a privileged operation.
 *	It returns 0 for success, -1 for failure.
 *
 *	If the implementation does not support setting the supplementary
 *	groups list, then setgrps() must return -1 with errno set to ENOSYS.
 */

public int
setgrps(ngrps, grparray)
int   ngrps;
gid_t grparray[];
{
	/* If setting supplementary groups is not supported replace
	   the line below with:

		errno = ENOSYS;
		return -1;
	*/

	return setgroups(ngrps, grparray);

	/* If setgroups() takes an array of integers of a different
	   size to gid_t, the gid_t array will need to be copied.
	   In this case, remove the line above and the #if/#endif
	   around the following, and alter the typedef as necesary:
	 */

#if 0
	typedef int GID_T;
	GID_T *gcopy, gdummy;
	int i, rval;

	if (ngrps > 0)
	{
		gcopy = (GID_T *)malloc((size_t)(ngrps * sizeof(GID_T)));
		if (gcopy == NULL)
			return -1;
	}
	else
		gcopy = &gdummy;

	for (i=0; i<ngrps; i++)
		gcopy[i] = grparray[i];

	rval = setgroups(ngrps, gcopy);

	if (ngrps > 0)
		free((void *)gcopy);

	return rval;
#endif /* 0 */
}

