static VALUE group_gr_put(VALUE self, VALUE io) { struct group grp; VALUE path; #ifdef HAVE_FGETGRENT struct group *tmp_grp; long i = 0; #endif Check_EU_Type(self, rb_cGroup); Check_Writes(io, FMODE_WRITABLE); path = RFILE_PATH(io); rewind(RFILE_FPTR(io)); grp.gr_name = RSTRING_PTR(rb_ivar_get(self, id_name)); #ifdef HAVE_FGETGRENT while ( (tmp_grp = fgetgrent(RFILE_FPTR(io))) ) if ( !strcmp(tmp_grp->gr_name, grp.gr_name) ) rb_raise(rb_eArgError, "%s is already mentioned in %s:%ld", tmp_grp->gr_name, StringValuePtr(path), ++i ); #endif grp.gr_passwd = RSTRING_PTR(rb_ivar_get(self, id_passwd)); grp.gr_gid = NUM2GIDT( rb_ivar_get(self, id_gid) ); grp.gr_mem = setup_char_members( rb_iv_get(self, "@members") ); if ( putgrent(&grp,RFILE_FPTR(io)) ) eu_errno(RFILE_PATH(io)); free_char_members(grp.gr_mem, (int)RARRAY_LEN( rb_iv_get(self, "@members") )); return Qtrue; }
/* call-seq: * getgrgid(group_id) -> Group * * Returns information about the group with specified integer +group_id+, * as found in /etc/group. * * The information is returned as a Group struct. * * See the unix manpage for <code>getgrgid(3)</code> for more detail. * * === Example: * * Etc.getgrgid(100) * #=> #<struct Etc::Group name="users", passwd="x", gid=100, mem=["meta", "root"]> * */ static VALUE etc_getgrgid(int argc, VALUE *argv, VALUE obj) { #ifdef HAVE_GETGRENT VALUE id; gid_t gid; struct group *grp; if (rb_scan_args(argc, argv, "01", &id) == 1) { gid = NUM2GIDT(id); } else { gid = getgid(); } grp = getgrgid(gid); if (grp == 0) rb_raise(rb_eArgError, "can't find group for %d", (int)gid); return setup_group(grp); #else return Qnil; #endif }