read()
public
Reads the next entry from dir and returns it as a string. Returns
nil at the end of the stream.
d = Dir.new("testdir")
d.read
d.read
d.read
Show source
static VALUE
dir_read(VALUE dir)
{
struct dir_data *dirp;
struct dirent *dp;
IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT entry);
GetDIR(dir, dirp);
errno = 0;
if (READDIR(dirp->dir, dirp->enc, &STRUCT_DIRENT(entry), dp)) {
return rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc);
}
else if (errno == 0) { /* end of stream */
return Qnil;
}
else {
rb_sys_fail(0);
}
return Qnil; /* not reached */
}