diff --git a/ChangeLog b/ChangeLog index 9891b1f30d..9e65879d92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,9 @@ -Tue Jan 9 17:48:38 2007 NAKAMURA Usaku +Tue Jan 9 12:29:20 2007 Nobuyoshi Nakada - * file.c (rb_find_file): should not call fpath_check() with NULL. - fixed: [ruby-core:09867] + * ext/etc/etc.c (etc_getpwuid, etc_getgrgid): fix to correctly + convert uid/gid from VALUE. + + * ext/etc/etc.c (etc_getpwuid): ditto. Tue Jan 9 03:54:38 2007 Yukihiro Matsumoto diff --git a/ext/etc/etc.c b/ext/etc/etc.c index 22907a5c44..a0e88612a9 100644 --- a/ext/etc/etc.c +++ b/ext/etc/etc.c @@ -125,16 +125,7 @@ etc_getpwuid(int argc, VALUE *argv, VALUE obj) rb_secure(4); if (rb_scan_args(argc, argv, "01", &id) == 1) { -#if HAVE_LONG_LONG && HAVE_TYPE_UID_T - if (sizeof(uid_t) > sizeof(int)) { - uid = NUM2ULL(id); - } - else { - uid = NUM2UINT(id); - } -#else - uid = NUM2UINT(id); -#endif + uid = PW_VAL2UID(id); } else { uid = getuid(); @@ -326,14 +317,20 @@ setup_group(struct group *grp) * */ static VALUE -etc_getgrgid(VALUE obj, VALUE id) +etc_getgrgid(int argc, VALUE *argv, VALUE obj) { #ifdef HAVE_GETGRENT - int gid; + VALUE id; + gid_t gid; struct group *grp; rb_secure(4); - gid = NUM2INT(id); + if (rb_scan_args(argc, argv, "01", &id) == 1) { + gid = PW_VAL2GID(id); + } + else { + gid = getgid(); + } grp = getgrgid(gid); if (grp == 0) rb_raise(rb_eArgError, "can't find group for %d", gid); return setup_group(grp); @@ -505,7 +502,7 @@ Init_etc(void) rb_define_module_function(mEtc, "getpwent", etc_getpwent, 0); rb_define_module_function(mEtc, "passwd", etc_passwd, 0); - rb_define_module_function(mEtc, "getgrgid", etc_getgrgid, 1); + rb_define_module_function(mEtc, "getgrgid", etc_getgrgid, -1); rb_define_module_function(mEtc, "getgrnam", etc_getgrnam, 1); rb_define_module_function(mEtc, "group", etc_group, 0); rb_define_module_function(mEtc, "setgrent", etc_setgrent, 0); diff --git a/ext/etc/extconf.rb b/ext/etc/extconf.rb index 2496d36aa1..dbd0672545 100644 --- a/ext/etc/extconf.rb +++ b/ext/etc/extconf.rb @@ -35,7 +35,9 @@ if a or b or c f = "U#{f}" end end - $defs.push("-DPW_#{t.chomp('_t').upcase}2VAL=#{f}") + t = t.chomp('_t').upcase + $defs.push("-DPW_#{t}2VAL=#{f}") + $defs.push("-DPW_VAL2#{t}=#{f.sub(/([A-Z]+)2(NUM)/, '\22\1')}") end create_makefile("etc") end