/* Provides a convenient Ruby iterator which executes a block for each entry
* in the /etc/passwd file.
*
* The code block is passed an Etc::Passwd struct; see getpwent above for
* details.
*
* Example:
*
* require 'etc'
*
* Etc.passwd {|u|
* puts u.name + " = " + u.gecos
* }
*
*/
static VALUE
etc_passwd(VALUE obj)
{
#ifdef HAVE_GETPWENT
struct passwd *pw;
rb_secure(4);
if (rb_block_given_p()) {
if (passwd_blocking) {
rb_raise(rb_eRuntimeError, "parallel passwd iteration");
}
passwd_blocking = Qtrue;
rb_ensure(passwd_iterate, 0, passwd_ensure, 0);
}
if (pw = getpwent()) {
return setup_passwd(pw);
}
#endif
return Qnil;
}