class method
Etc.getpwuid
(?::Integer uid) -> ::Etc::Passwd
getpwuid(uid) → Etc::Passwd
ext/etc/etc.c
View on GitHub ↗
static VALUE
etc_getpwuid(int argc, VALUE *argv, VALUE obj)
{
#if defined(HAVE_GETPWENT)
VALUE id;
rb_uid_t uid;
struct passwd *pwd;
if (rb_scan_args(argc, argv, "01", &id) == 1) {
uid = NUM2UIDT(id);
}
else {
uid = getuid();
}
pwd = getpwuid(uid);
if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %d", (int)uid);
return setup_passwd(pwd);
#else
return Qnil;
#endif
}
Returns the /etc/passwd information for the user with the given integer uid.
The information is returned as a Passwd struct.
If uid is omitted, the value from Passwd[:uid] is returned instead.
See the unix manpage for getpwuid(3) for more detail.
Example:
Example
Etc.getpwuid(0) #=> #<struct Etc::Passwd name="root", passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash">