33static VALUE rb_cPathname ;
44static ID id_at_path ;
55static ID id_sub ;
6+ static ID id_realdirpath ;
67
78static VALUE
89get_strpath (VALUE obj )
@@ -83,6 +84,22 @@ path_sub(int argc, VALUE *argv, VALUE self)
8384 return rb_class_new_instance (1 , & str , rb_obj_class (self ));
8485}
8586
87+ /*
88+ * Returns the real (absolute) pathname of +self+ in the actual filesystem.
89+ *
90+ * Does not contain symlinks or useless dots, +..+ and +.+.
91+ *
92+ * The last component of the real pathname can be nonexistent.
93+ */
94+ static VALUE
95+ path_realdirpath (int argc , VALUE * argv , VALUE self )
96+ {
97+ VALUE basedir , str ;
98+ rb_scan_args (argc , argv , "01" , & basedir );
99+ str = rb_funcall (rb_cFile , id_realdirpath , 2 , get_strpath (self ), basedir );
100+ return rb_class_new_instance (1 , & str , rb_obj_class (self ));
101+ }
102+
86103static void init_ids (void );
87104
88105void
@@ -102,6 +119,7 @@ InitVM_pathname(void)
102119 rb_cPathname = rb_define_class ("Pathname" , rb_cObject );
103120 rb_define_method (rb_cPathname , "<=>" , path_cmp , 1 );
104121 rb_define_method (rb_cPathname , "sub" , path_sub , -1 );
122+ rb_define_method (rb_cPathname , "realdirpath" , path_realdirpath , -1 );
105123}
106124
107125void
@@ -110,4 +128,5 @@ init_ids(void)
110128#undef rb_intern
111129 id_at_path = rb_intern ("@path" );
112130 id_sub = rb_intern ("sub" );
131+ id_realdirpath = rb_intern ("realdirpath" );
113132}
0 commit comments