summaryrefslogtreecommitdiff
path: root/ext/pathname/pathname.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-01 11:57:58 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-01 11:57:58 +0000
commitc29b801afad1dc5cb4227bcef9e4bc004c967b8a (patch)
tree00e5459fe9a17e944a0b26ed6e9bcbf8e7314b0d /ext/pathname/pathname.c
parentb496cd64e5c8a588f19ff699beda175e2d453d72 (diff)
* ext/pathname/pathname.c (path_realpath): Pathname#realpath translated
from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/pathname/pathname.c')
-rw-r--r--ext/pathname/pathname.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c
index ecfe11cfc8..273ecee07c 100644
--- a/ext/pathname/pathname.c
+++ b/ext/pathname/pathname.c
@@ -199,6 +199,23 @@ path_sub_ext(VALUE self, VALUE repl)
}
/*
+ * Returns the real (absolute) pathname of +self+ in the actual
+ * filesystem not containing symlinks or useless dots.
+ *
+ * All components of the pathname must exist when this method is
+ * called.
+ *
+ */
+static VALUE
+path_realpath(int argc, VALUE *argv, VALUE self)
+{
+ VALUE basedir, str;
+ rb_scan_args(argc, argv, "01", &basedir);
+ str = rb_funcall(rb_cFile, rb_intern("realpath"), 2, get_strpath(self), basedir);
+ return rb_class_new_instance(1, &str, rb_obj_class(self));
+}
+
+/*
* == Pathname
*
* Pathname represents a pathname which locates a file in a filesystem.
@@ -396,4 +413,5 @@ Init_pathname()
rb_define_method(rb_cPathname, "inspect", path_inspect, 0);
rb_define_method(rb_cPathname, "sub", path_sub, -1);
rb_define_method(rb_cPathname, "sub_ext", path_sub_ext, 1);
+ rb_define_method(rb_cPathname, "realpath", path_realpath, -1);
}