Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implment Dir#fileno with a Rubinius primitive
Browse files Browse the repository at this point in the history
tak1n committed May 27, 2015
1 parent 2958f37 commit 7111811
Showing 4 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions kernel/common/dir.rb
Original file line number Diff line number Diff line change
@@ -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
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
Original file line number Diff line number Diff line change
@@ -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);

3 changes: 3 additions & 0 deletions vm/builtin/dir.hpp
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 7111811

Please sign in to comment.