groups=(p1)
public
Show source
static VALUE
proc_setgroups(VALUE obj, VALUE ary)
{
size_t ngroups;
rb_gid_t *groups;
int i;
struct group *gr;
Check_Type(ary, T_ARRAY);
ngroups = RARRAY_LEN(ary);
if (ngroups > maxgroups)
rb_raise(rb_eArgError, "too many groups, %lu max", (unsigned long)maxgroups);
groups = ALLOCA_N(rb_gid_t, ngroups);
for (i = 0; i < ngroups && i < RARRAY_LEN(ary); i++) {
VALUE g = RARRAY_PTR(ary)[i];
if (FIXNUM_P(g)) {
groups[i] = NUM2GIDT(g);
}
else {
VALUE tmp = rb_check_string_type(g);
if (NIL_P(tmp)) {
groups[i] = NUM2GIDT(g);
}
else {
gr = getgrnam(RSTRING_PTR(tmp));
if (gr == NULL)
rb_raise(rb_eArgError,
"can't find group for %s", RSTRING_PTR(tmp));
groups[i] = gr->gr_gid;
}
}
}
i = setgroups(ngroups, groups);
if (i == -1)
rb_sys_fail(0);
return proc_getgroups(obj);
rb_notimplement();
return Qnil;
}