Skip to content

Commit

Permalink
Implment Dir#fileno with a Rubinius primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
tak1n committed May 27, 2015
1 parent 2958f37 commit 7111811
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions kernel/common/dir.rb
Expand Up @@ -174,6 +174,11 @@ def each
self
end

def fileno
Rubinius.primitive :dir_fileno
raise PrimitiveFailure, "Dir#fileno primitive failed"
end

attr_reader :path

alias_method :to_path, :path
Expand Down
2 changes: 0 additions & 2 deletions spec/tags/ruby/core/dir/fileno_tags.txt

This file was deleted.

6 changes: 6 additions & 0 deletions vm/builtin/dir.cpp
Expand Up @@ -71,6 +71,12 @@ namespace rubinius {
return cTrue;
}

Object* Dir::fileno(STATE) {
int fd = dirfd(os_);

return Fixnum::from(fd);
}

Object* Dir::close(STATE) {
guard(state);

Expand Down
3 changes: 3 additions & 0 deletions vm/builtin/dir.hpp
Expand Up @@ -36,6 +36,9 @@ namespace rubinius {
// Rubinius.primitive :dir_open
Object* open(STATE, String *path, Object* enc);

// Rubinius.primitive :dir_fileno
Object* fileno(STATE);

// Rubinius.primitive :dir_close
Object* close(STATE);

Expand Down

0 comments on commit 7111811

Please sign in to comment.