ext/pathname/pathname.c

Go to the documentation of this file.
00001 #include "ruby.h"
00002 #include "ruby/encoding.h"
00003 
00004 static VALUE rb_cPathname;
00005 static ID id_at_path, id_to_path;
00006 
00007 static VALUE
00008 get_strpath(VALUE obj)
00009 {
00010     VALUE strpath;
00011     strpath = rb_ivar_get(obj, id_at_path);
00012     if (!RB_TYPE_P(strpath, T_STRING))
00013         rb_raise(rb_eTypeError, "unexpected @path");
00014     return strpath;
00015 }
00016 
00017 static void
00018 set_strpath(VALUE obj, VALUE val)
00019 {
00020     rb_ivar_set(obj, id_at_path, val);
00021 }
00022 
00023 /*
00024  * Create a Pathname object from the given String (or String-like object).
00025  * If +path+ contains a NULL character (<tt>\0</tt>), an ArgumentError is raised.
00026  */
00027 static VALUE
00028 path_initialize(VALUE self, VALUE arg)
00029 {
00030     VALUE str;
00031     if (RB_TYPE_P(arg, T_STRING)) {
00032         str = arg;
00033     }
00034     else {
00035         str = rb_check_funcall(arg, id_to_path, 0, NULL);
00036         if (str == Qundef)
00037             str = arg;
00038         StringValue(str);
00039     }
00040     if (memchr(RSTRING_PTR(str), '\0', RSTRING_LEN(str)))
00041         rb_raise(rb_eArgError, "pathname contains null byte");
00042     str = rb_obj_dup(str);
00043 
00044     set_strpath(self, str);
00045     OBJ_INFECT(self, str);
00046     return self;
00047 }
00048 
00049 /*
00050  * call-seq:
00051  *   pathname.freeze -> obj
00052  *
00053  * Freezes this Pathname.
00054  *
00055  * See Object.freeze.
00056  */
00057 static VALUE
00058 path_freeze(VALUE self)
00059 {
00060     rb_call_super(0, 0);
00061     rb_str_freeze(get_strpath(self));
00062     return self;
00063 }
00064 
00065 /*
00066  * call-seq:
00067  *   pathname.taint -> obj
00068  *
00069  * Taints this Pathname.
00070  *
00071  * See Object.taint.
00072  */
00073 static VALUE
00074 path_taint(VALUE self)
00075 {
00076     rb_call_super(0, 0);
00077     rb_obj_taint(get_strpath(self));
00078     return self;
00079 }
00080 
00081 /*
00082  * call-seq:
00083  *   pathname.untaint -> obj
00084  *
00085  * Untaints this Pathname.
00086  *
00087  * See Object.untaint.
00088  */
00089 static VALUE
00090 path_untaint(VALUE self)
00091 {
00092     rb_call_super(0, 0);
00093     rb_obj_untaint(get_strpath(self));
00094     return self;
00095 }
00096 
00097 /*
00098  *  Compare this pathname with +other+.  The comparison is string-based.
00099  *  Be aware that two different paths (<tt>foo.txt</tt> and <tt>./foo.txt</tt>)
00100  *  can refer to the same file.
00101  */
00102 static VALUE
00103 path_eq(VALUE self, VALUE other)
00104 {
00105     if (!rb_obj_is_kind_of(other, rb_cPathname))
00106         return Qfalse;
00107     return rb_str_equal(get_strpath(self), get_strpath(other));
00108 }
00109 
00110 /*
00111  *  Provides a case-sensitive comparison operator for pathnames.
00112  *
00113  *      Pathname.new('/usr') <=> Pathname.new('/usr/bin')
00114  *          #=> -1
00115  *      Pathname.new('/usr/bin') <=> Pathname.new('/usr/bin')
00116  *          #=> 0
00117  *      Pathname.new('/usr/bin') <=> Pathname.new('/USR/BIN')
00118  *          #=> 1
00119  *
00120  *  It will return +-1+, +0+ or +1+ depending on the value of the left argument
00121  *  relative to the right argument. Or it will return +nil+ if the arguments
00122  *  are not comparable.
00123  */
00124 static VALUE
00125 path_cmp(VALUE self, VALUE other)
00126 {
00127     VALUE s1, s2;
00128     char *p1, *p2;
00129     char *e1, *e2;
00130     if (!rb_obj_is_kind_of(other, rb_cPathname))
00131         return Qnil;
00132     s1 = get_strpath(self);
00133     s2 = get_strpath(other);
00134     p1 = RSTRING_PTR(s1);
00135     p2 = RSTRING_PTR(s2);
00136     e1 = p1 + RSTRING_LEN(s1);
00137     e2 = p2 + RSTRING_LEN(s2);
00138     while (p1 < e1 && p2 < e2) {
00139         int c1, c2;
00140         c1 = (unsigned char)*p1++;
00141         c2 = (unsigned char)*p2++;
00142         if (c1 == '/') c1 = '\0';
00143         if (c2 == '/') c2 = '\0';
00144         if (c1 != c2) {
00145             if (c1 < c2)
00146                 return INT2FIX(-1);
00147             else
00148                 return INT2FIX(1);
00149         }
00150     }
00151     if (p1 < e1)
00152         return INT2FIX(1);
00153     if (p2 < e2)
00154         return INT2FIX(-1);
00155     return INT2FIX(0);
00156 }
00157 
00158 /* :nodoc: */
00159 static VALUE
00160 path_hash(VALUE self)
00161 {
00162     return INT2FIX(rb_str_hash(get_strpath(self)));
00163 }
00164 
00165 /*
00166  *  call-seq:
00167  *    pathname.to_s             -> string
00168  *    pathname.to_path          -> string
00169  *
00170  *  Return the path as a String.
00171  *
00172  *  to_path is implemented so Pathname objects are usable with File.open, etc.
00173  */
00174 static VALUE
00175 path_to_s(VALUE self)
00176 {
00177     return rb_obj_dup(get_strpath(self));
00178 }
00179 
00180 /* :nodoc: */
00181 static VALUE
00182 path_inspect(VALUE self)
00183 {
00184     const char *c = rb_obj_classname(self);
00185     VALUE str = get_strpath(self);
00186     return rb_sprintf("#<%s:%"PRIsVALUE">", c, str);
00187 }
00188 
00189 /*
00190  * Return a pathname which is substituted by String#sub.
00191  *
00192  *      path1 = Pathname.new('/usr/bin/perl')
00193  *      path1.sub('perl', 'ruby')
00194  *          #=> #<Pathname:/usr/bin/ruby>
00195  */
00196 static VALUE
00197 path_sub(int argc, VALUE *argv, VALUE self)
00198 {
00199     VALUE str = get_strpath(self);
00200 
00201     if (rb_block_given_p()) {
00202         str = rb_block_call(str, rb_intern("sub"), argc, argv, 0, 0);
00203     }
00204     else {
00205         str = rb_funcall2(str, rb_intern("sub"), argc, argv);
00206     }
00207     return rb_class_new_instance(1, &str, rb_obj_class(self));
00208 }
00209 
00210 /*
00211  * Return a pathname with +repl+ added as a suffix to the basename.
00212  *
00213  * If self has no extension part, +repl+ is appended.
00214  *
00215  *      Pathname.new('/usr/bin/shutdown').sub_ext('.rb')
00216  *          #=> #<Pathname:/usr/bin/shutdown.rb>
00217  */
00218 static VALUE
00219 path_sub_ext(VALUE self, VALUE repl)
00220 {
00221     VALUE str = get_strpath(self);
00222     VALUE str2;
00223     long extlen;
00224     const char *ext;
00225     const char *p;
00226 
00227     StringValue(repl);
00228     p = RSTRING_PTR(str);
00229     extlen = RSTRING_LEN(str);
00230     ext = ruby_enc_find_extname(p, &extlen, rb_enc_get(str));
00231     if (ext == NULL) {
00232         ext = p + RSTRING_LEN(str);
00233     }
00234     else if (extlen <= 1) {
00235         ext += extlen;
00236     }
00237     str2 = rb_str_subseq(str, 0, ext-p);
00238     rb_str_append(str2, repl);
00239     OBJ_INFECT(str2, str);
00240     return rb_class_new_instance(1, &str2, rb_obj_class(self));
00241 }
00242 
00243 /* Facade for File */
00244 
00245 /*
00246  * Returns the real (absolute) pathname for +self+ in the actual
00247  * filesystem.
00248  *
00249  * Does not contain symlinks or useless dots, +..+ and +.+.
00250  *
00251  * All components of the pathname must exist when this method is
00252  * called.
00253  *
00254  */
00255 static VALUE
00256 path_realpath(int argc, VALUE *argv, VALUE self)
00257 {
00258     VALUE basedir, str;
00259     rb_scan_args(argc, argv, "01", &basedir);
00260     str = rb_funcall(rb_cFile, rb_intern("realpath"), 2, get_strpath(self), basedir);
00261     return rb_class_new_instance(1, &str, rb_obj_class(self));
00262 }
00263 
00264 /*
00265  * Returns the real (absolute) pathname of +self+ in the actual filesystem.
00266  *
00267  * Does not contain symlinks or useless dots, +..+ and +.+.
00268  *
00269  * The last component of the real pathname can be nonexistent.
00270  */
00271 static VALUE
00272 path_realdirpath(int argc, VALUE *argv, VALUE self)
00273 {
00274     VALUE basedir, str;
00275     rb_scan_args(argc, argv, "01", &basedir);
00276     str = rb_funcall(rb_cFile, rb_intern("realdirpath"), 2, get_strpath(self), basedir);
00277     return rb_class_new_instance(1, &str, rb_obj_class(self));
00278 }
00279 
00280 /*
00281  * call-seq:
00282  *   pathname.each_line {|line| ... }
00283  *   pathname.each_line(sep=$/ [, open_args]) {|line| block }     -> nil
00284  *   pathname.each_line(limit [, open_args]) {|line| block }      -> nil
00285  *   pathname.each_line(sep, limit [, open_args]) {|line| block } -> nil
00286  *   pathname.each_line(...)                                      -> an_enumerator
00287  *
00288  * Iterates over each line in the file and yields a String object for each.
00289  */
00290 static VALUE
00291 path_each_line(int argc, VALUE *argv, VALUE self)
00292 {
00293     VALUE args[4];
00294     int n;
00295 
00296     args[0] = get_strpath(self);
00297     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
00298     if (rb_block_given_p()) {
00299         return rb_block_call(rb_cIO, rb_intern("foreach"), 1+n, args, 0, 0);
00300     }
00301     else {
00302         return rb_funcall2(rb_cIO, rb_intern("foreach"), 1+n, args);
00303     }
00304 }
00305 
00306 /*
00307  * call-seq:
00308  *   pathname.read([length [, offset]]) -> string
00309  *   pathname.read([length [, offset]], open_args) -> string
00310  *
00311  * Returns all data from the file, or the first +N+ bytes if specified.
00312  *
00313  * See IO.read.
00314  *
00315  */
00316 static VALUE
00317 path_read(int argc, VALUE *argv, VALUE self)
00318 {
00319     VALUE args[4];
00320     int n;
00321 
00322     args[0] = get_strpath(self);
00323     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
00324     return rb_funcall2(rb_cIO, rb_intern("read"), 1+n, args);
00325 }
00326 
00327 /*
00328  * call-seq:
00329  *   pathname.binread([length [, offset]]) -> string
00330  *
00331  * Returns all the bytes from the file, or the first +N+ if specified.
00332  *
00333  * See IO.binread.
00334  *
00335  */
00336 static VALUE
00337 path_binread(int argc, VALUE *argv, VALUE self)
00338 {
00339     VALUE args[3];
00340     int n;
00341 
00342     args[0] = get_strpath(self);
00343     n = rb_scan_args(argc, argv, "02", &args[1], &args[2]);
00344     return rb_funcall2(rb_cIO, rb_intern("binread"), 1+n, args);
00345 }
00346 
00347 /*
00348  * call-seq:
00349  *   pathname.write(string, [offset] )   => fixnum
00350  *   pathname.write(string, [offset], open_args )   => fixnum
00351  *
00352  * Writes +contents+ to the file.
00353  *
00354  * See IO.write.
00355  *
00356  */
00357 static VALUE
00358 path_write(int argc, VALUE *argv, VALUE self)
00359 {
00360     VALUE args[4];
00361     int n;
00362 
00363     args[0] = get_strpath(self);
00364     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
00365     return rb_funcall2(rb_cIO, rb_intern("write"), 1+n, args);
00366 }
00367 
00368 /*
00369  * call-seq:
00370  *   pathname.binwrite(string, [offset] )   => fixnum
00371  *   pathname.binwrite(string, [offset], open_args )   => fixnum
00372  *
00373  * Writes +contents+ to the file, opening it in binary mode.
00374  *
00375  * See IO.binwrite.
00376  *
00377  */
00378 static VALUE
00379 path_binwrite(int argc, VALUE *argv, VALUE self)
00380 {
00381     VALUE args[4];
00382     int n;
00383 
00384     args[0] = get_strpath(self);
00385     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
00386     return rb_funcall2(rb_cIO, rb_intern("binwrite"), 1+n, args);
00387 }
00388 
00389 /*
00390  * call-seq:
00391  *   pathname.readlines(sep=$/ [, open_args])     -> array
00392  *   pathname.readlines(limit [, open_args])      -> array
00393  *   pathname.readlines(sep, limit [, open_args]) -> array
00394  *
00395  * Returns all the lines from the file.
00396  *
00397  * See IO.readlines.
00398  *
00399  */
00400 static VALUE
00401 path_readlines(int argc, VALUE *argv, VALUE self)
00402 {
00403     VALUE args[4];
00404     int n;
00405 
00406     args[0] = get_strpath(self);
00407     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
00408     return rb_funcall2(rb_cIO, rb_intern("readlines"), 1+n, args);
00409 }
00410 
00411 /*
00412  * call-seq:
00413  *   pathname.sysopen([mode, [perm]])  -> fixnum
00414  *
00415  * See IO.sysopen.
00416  *
00417  */
00418 static VALUE
00419 path_sysopen(int argc, VALUE *argv, VALUE self)
00420 {
00421     VALUE args[3];
00422     int n;
00423 
00424     args[0] = get_strpath(self);
00425     n = rb_scan_args(argc, argv, "02", &args[1], &args[2]);
00426     return rb_funcall2(rb_cIO, rb_intern("sysopen"), 1+n, args);
00427 }
00428 
00429 /*
00430  * call-seq:
00431  *   pathname.atime     -> time
00432  *
00433  * Returns the last access time for the file.
00434  *
00435  * See File.atime.
00436  */
00437 static VALUE
00438 path_atime(VALUE self)
00439 {
00440     return rb_funcall(rb_cFile, rb_intern("atime"), 1, get_strpath(self));
00441 }
00442 
00443 /*
00444  * call-seq:
00445  *   pathname.ctime     -> time
00446  *
00447  * Returns the last change time, using directory information, not the file itself.
00448  *
00449  * See File.ctime.
00450  */
00451 static VALUE
00452 path_ctime(VALUE self)
00453 {
00454     return rb_funcall(rb_cFile, rb_intern("ctime"), 1, get_strpath(self));
00455 }
00456 
00457 /*
00458  * call-seq:
00459  *   pathname.mtime     -> time
00460  *
00461  * Returns the last modified time of the file.
00462  *
00463  * See File.mtime.
00464  */
00465 static VALUE
00466 path_mtime(VALUE self)
00467 {
00468     return rb_funcall(rb_cFile, rb_intern("mtime"), 1, get_strpath(self));
00469 }
00470 
00471 /*
00472  * call-seq:
00473  *   pathname.chmod     -> integer
00474  *
00475  * Changes file permissions.
00476  *
00477  * See File.chmod.
00478  */
00479 static VALUE
00480 path_chmod(VALUE self, VALUE mode)
00481 {
00482     return rb_funcall(rb_cFile, rb_intern("chmod"), 2, mode, get_strpath(self));
00483 }
00484 
00485 /*
00486  * call-seq:
00487  *   pathname.lchmod    -> integer
00488  *
00489  * Same as Pathname.chmod, but does not follow symbolic links.
00490  *
00491  * See File.lchmod.
00492  */
00493 static VALUE
00494 path_lchmod(VALUE self, VALUE mode)
00495 {
00496     return rb_funcall(rb_cFile, rb_intern("lchmod"), 2, mode, get_strpath(self));
00497 }
00498 
00499 /*
00500  * call-seq:
00501  *   pathname.chown     -> integer
00502  *
00503  * Change owner and group of the file.
00504  *
00505  * See File.chown.
00506  */
00507 static VALUE
00508 path_chown(VALUE self, VALUE owner, VALUE group)
00509 {
00510     return rb_funcall(rb_cFile, rb_intern("chown"), 3, owner, group, get_strpath(self));
00511 }
00512 
00513 /*
00514  * call-seq:
00515  *   pathname.lchown    -> integer
00516  *
00517  * Same as Pathname.chown, but does not follow symbolic links.
00518  *
00519  * See File.lchown.
00520  */
00521 static VALUE
00522 path_lchown(VALUE self, VALUE owner, VALUE group)
00523 {
00524     return rb_funcall(rb_cFile, rb_intern("lchown"), 3, owner, group, get_strpath(self));
00525 }
00526 
00527 /*
00528  * call-seq:
00529  *    pathname.fnmatch(pattern, [flags])        -> string
00530  *    pathname.fnmatch?(pattern, [flags])       -> string
00531  *
00532  * Return +true+ if the receiver matches the given pattern.
00533  *
00534  * See File.fnmatch.
00535  */
00536 static VALUE
00537 path_fnmatch(int argc, VALUE *argv, VALUE self)
00538 {
00539     VALUE str = get_strpath(self);
00540     VALUE pattern, flags;
00541     if (rb_scan_args(argc, argv, "11", &pattern, &flags) == 1)
00542         return rb_funcall(rb_cFile, rb_intern("fnmatch"), 2, pattern, str);
00543     else
00544         return rb_funcall(rb_cFile, rb_intern("fnmatch"), 3, pattern, str, flags);
00545 }
00546 
00547 /*
00548  * call-seq:
00549  *   pathname.ftype     -> string
00550  *
00551  * Returns "type" of file ("file", "directory", etc).
00552  *
00553  * See File.ftype.
00554  */
00555 static VALUE
00556 path_ftype(VALUE self)
00557 {
00558     return rb_funcall(rb_cFile, rb_intern("ftype"), 1, get_strpath(self));
00559 }
00560 
00561 /*
00562  * call-seq:
00563  *   pathname.make_link(old)
00564  *
00565  * Creates a hard link at _pathname_.
00566  *
00567  * See File.link.
00568  */
00569 static VALUE
00570 path_make_link(VALUE self, VALUE old)
00571 {
00572     return rb_funcall(rb_cFile, rb_intern("link"), 2, old, get_strpath(self));
00573 }
00574 
00575 /*
00576  * Opens the file for reading or writing.
00577  *
00578  * See File.open.
00579  */
00580 static VALUE
00581 path_open(int argc, VALUE *argv, VALUE self)
00582 {
00583     VALUE args[4];
00584     int n;
00585 
00586     args[0] = get_strpath(self);
00587     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
00588     if (rb_block_given_p()) {
00589         return rb_block_call(rb_cFile, rb_intern("open"), 1+n, args, 0, 0);
00590     }
00591     else {
00592         return rb_funcall2(rb_cFile, rb_intern("open"), 1+n, args);
00593     }
00594 }
00595 
00596 /*
00597  * Read symbolic link.
00598  *
00599  * See File.readlink.
00600  */
00601 static VALUE
00602 path_readlink(VALUE self)
00603 {
00604     VALUE str;
00605     str = rb_funcall(rb_cFile, rb_intern("readlink"), 1, get_strpath(self));
00606     return rb_class_new_instance(1, &str, rb_obj_class(self));
00607 }
00608 
00609 /*
00610  * Rename the file.
00611  *
00612  * See File.rename.
00613  */
00614 static VALUE
00615 path_rename(VALUE self, VALUE to)
00616 {
00617     return rb_funcall(rb_cFile, rb_intern("rename"), 2, get_strpath(self), to);
00618 }
00619 
00620 /*
00621  * Returns a File::Stat object.
00622  *
00623  * See File.stat.
00624  */
00625 static VALUE
00626 path_stat(VALUE self)
00627 {
00628     return rb_funcall(rb_cFile, rb_intern("stat"), 1, get_strpath(self));
00629 }
00630 
00631 /*
00632  * See File.lstat.
00633  */
00634 static VALUE
00635 path_lstat(VALUE self)
00636 {
00637     return rb_funcall(rb_cFile, rb_intern("lstat"), 1, get_strpath(self));
00638 }
00639 
00640 /*
00641  * call-seq:
00642  *   pathname.make_symlink(old)
00643  *
00644  * Creates a symbolic link.
00645  *
00646  * See File.symlink.
00647  */
00648 static VALUE
00649 path_make_symlink(VALUE self, VALUE old)
00650 {
00651     return rb_funcall(rb_cFile, rb_intern("symlink"), 2, old, get_strpath(self));
00652 }
00653 
00654 /*
00655  * Truncates the file to +length+ bytes.
00656  *
00657  * See File.truncate.
00658  */
00659 static VALUE
00660 path_truncate(VALUE self, VALUE length)
00661 {
00662     return rb_funcall(rb_cFile, rb_intern("truncate"), 2, get_strpath(self), length);
00663 }
00664 
00665 /*
00666  * Update the access and modification times of the file.
00667  *
00668  * See File.utime.
00669  */
00670 static VALUE
00671 path_utime(VALUE self, VALUE atime, VALUE mtime)
00672 {
00673     return rb_funcall(rb_cFile, rb_intern("utime"), 3, atime, mtime, get_strpath(self));
00674 }
00675 
00676 /*
00677  * Returns the last component of the path.
00678  *
00679  * See File.basename.
00680  */
00681 static VALUE
00682 path_basename(int argc, VALUE *argv, VALUE self)
00683 {
00684     VALUE str = get_strpath(self);
00685     VALUE fext;
00686     if (rb_scan_args(argc, argv, "01", &fext) == 0)
00687         str = rb_funcall(rb_cFile, rb_intern("basename"), 1, str);
00688     else
00689         str = rb_funcall(rb_cFile, rb_intern("basename"), 2, str, fext);
00690     return rb_class_new_instance(1, &str, rb_obj_class(self));
00691 }
00692 
00693 /*
00694  * Returns all but the last component of the path.
00695  *
00696  * See File.dirname.
00697  */
00698 static VALUE
00699 path_dirname(VALUE self)
00700 {
00701     VALUE str = get_strpath(self);
00702     str = rb_funcall(rb_cFile, rb_intern("dirname"), 1, str);
00703     return rb_class_new_instance(1, &str, rb_obj_class(self));
00704 }
00705 
00706 /*
00707  * Returns the file's extension.
00708  *
00709  * See File.extname.
00710  */
00711 static VALUE
00712 path_extname(VALUE self)
00713 {
00714     VALUE str = get_strpath(self);
00715     return rb_funcall(rb_cFile, rb_intern("extname"), 1, str);
00716 }
00717 
00718 /*
00719  * Returns the absolute path for the file.
00720  *
00721  * See File.expand_path.
00722  */
00723 static VALUE
00724 path_expand_path(int argc, VALUE *argv, VALUE self)
00725 {
00726     VALUE str = get_strpath(self);
00727     VALUE dname;
00728     if (rb_scan_args(argc, argv, "01", &dname) == 0)
00729         str = rb_funcall(rb_cFile, rb_intern("expand_path"), 1, str);
00730     else
00731         str = rb_funcall(rb_cFile, rb_intern("expand_path"), 2, str, dname);
00732     return rb_class_new_instance(1, &str, rb_obj_class(self));
00733 }
00734 
00735 /*
00736  * Returns the #dirname and the #basename in an Array.
00737  *
00738  * See File.split.
00739  */
00740 static VALUE
00741 path_split(VALUE self)
00742 {
00743     VALUE str = get_strpath(self);
00744     VALUE ary, dirname, basename;
00745     ary = rb_funcall(rb_cFile, rb_intern("split"), 1, str);
00746     ary = rb_check_array_type(ary);
00747     dirname = rb_ary_entry(ary, 0);
00748     basename = rb_ary_entry(ary, 1);
00749     dirname = rb_class_new_instance(1, &dirname, rb_obj_class(self));
00750     basename = rb_class_new_instance(1, &basename, rb_obj_class(self));
00751     return rb_ary_new3(2, dirname, basename);
00752 }
00753 
00754 /*
00755  * See FileTest.blockdev?.
00756  */
00757 static VALUE
00758 path_blockdev_p(VALUE self)
00759 {
00760     return rb_funcall(rb_mFileTest, rb_intern("blockdev?"), 1, get_strpath(self));
00761 }
00762 
00763 /*
00764  * See FileTest.chardev?.
00765  */
00766 static VALUE
00767 path_chardev_p(VALUE self)
00768 {
00769     return rb_funcall(rb_mFileTest, rb_intern("chardev?"), 1, get_strpath(self));
00770 }
00771 
00772 /*
00773  * See FileTest.executable?.
00774  */
00775 static VALUE
00776 path_executable_p(VALUE self)
00777 {
00778     return rb_funcall(rb_mFileTest, rb_intern("executable?"), 1, get_strpath(self));
00779 }
00780 
00781 /*
00782  * See FileTest.executable_real?.
00783  */
00784 static VALUE
00785 path_executable_real_p(VALUE self)
00786 {
00787     return rb_funcall(rb_mFileTest, rb_intern("executable_real?"), 1, get_strpath(self));
00788 }
00789 
00790 /*
00791  * See FileTest.exist?.
00792  */
00793 static VALUE
00794 path_exist_p(VALUE self)
00795 {
00796     return rb_funcall(rb_mFileTest, rb_intern("exist?"), 1, get_strpath(self));
00797 }
00798 
00799 /*
00800  * See FileTest.grpowned?.
00801  */
00802 static VALUE
00803 path_grpowned_p(VALUE self)
00804 {
00805     return rb_funcall(rb_mFileTest, rb_intern("grpowned?"), 1, get_strpath(self));
00806 }
00807 
00808 /*
00809  * See FileTest.directory?.
00810  */
00811 static VALUE
00812 path_directory_p(VALUE self)
00813 {
00814     return rb_funcall(rb_mFileTest, rb_intern("directory?"), 1, get_strpath(self));
00815 }
00816 
00817 /*
00818  * See FileTest.file?.
00819  */
00820 static VALUE
00821 path_file_p(VALUE self)
00822 {
00823     return rb_funcall(rb_mFileTest, rb_intern("file?"), 1, get_strpath(self));
00824 }
00825 
00826 /*
00827  * See FileTest.pipe?.
00828  */
00829 static VALUE
00830 path_pipe_p(VALUE self)
00831 {
00832     return rb_funcall(rb_mFileTest, rb_intern("pipe?"), 1, get_strpath(self));
00833 }
00834 
00835 /*
00836  * See FileTest.socket?.
00837  */
00838 static VALUE
00839 path_socket_p(VALUE self)
00840 {
00841     return rb_funcall(rb_mFileTest, rb_intern("socket?"), 1, get_strpath(self));
00842 }
00843 
00844 /*
00845  * See FileTest.owned?.
00846  */
00847 static VALUE
00848 path_owned_p(VALUE self)
00849 {
00850     return rb_funcall(rb_mFileTest, rb_intern("owned?"), 1, get_strpath(self));
00851 }
00852 
00853 /*
00854  * See FileTest.readable?.
00855  */
00856 static VALUE
00857 path_readable_p(VALUE self)
00858 {
00859     return rb_funcall(rb_mFileTest, rb_intern("readable?"), 1, get_strpath(self));
00860 }
00861 
00862 /*
00863  * See FileTest.world_readable?.
00864  */
00865 static VALUE
00866 path_world_readable_p(VALUE self)
00867 {
00868     return rb_funcall(rb_mFileTest, rb_intern("world_readable?"), 1, get_strpath(self));
00869 }
00870 
00871 /*
00872  * See FileTest.readable_real?.
00873  */
00874 static VALUE
00875 path_readable_real_p(VALUE self)
00876 {
00877     return rb_funcall(rb_mFileTest, rb_intern("readable_real?"), 1, get_strpath(self));
00878 }
00879 
00880 /*
00881  * See FileTest.setuid?.
00882  */
00883 static VALUE
00884 path_setuid_p(VALUE self)
00885 {
00886     return rb_funcall(rb_mFileTest, rb_intern("setuid?"), 1, get_strpath(self));
00887 }
00888 
00889 /*
00890  * See FileTest.setgid?.
00891  */
00892 static VALUE
00893 path_setgid_p(VALUE self)
00894 {
00895     return rb_funcall(rb_mFileTest, rb_intern("setgid?"), 1, get_strpath(self));
00896 }
00897 
00898 /*
00899  * See FileTest.size.
00900  */
00901 static VALUE
00902 path_size(VALUE self)
00903 {
00904     return rb_funcall(rb_mFileTest, rb_intern("size"), 1, get_strpath(self));
00905 }
00906 
00907 /*
00908  * See FileTest.size?.
00909  */
00910 static VALUE
00911 path_size_p(VALUE self)
00912 {
00913     return rb_funcall(rb_mFileTest, rb_intern("size?"), 1, get_strpath(self));
00914 }
00915 
00916 /*
00917  * See FileTest.sticky?.
00918  */
00919 static VALUE
00920 path_sticky_p(VALUE self)
00921 {
00922     return rb_funcall(rb_mFileTest, rb_intern("sticky?"), 1, get_strpath(self));
00923 }
00924 
00925 /*
00926  * See FileTest.symlink?.
00927  */
00928 static VALUE
00929 path_symlink_p(VALUE self)
00930 {
00931     return rb_funcall(rb_mFileTest, rb_intern("symlink?"), 1, get_strpath(self));
00932 }
00933 
00934 /*
00935  * See FileTest.writable?.
00936  */
00937 static VALUE
00938 path_writable_p(VALUE self)
00939 {
00940     return rb_funcall(rb_mFileTest, rb_intern("writable?"), 1, get_strpath(self));
00941 }
00942 
00943 /*
00944  * See FileTest.world_writable?.
00945  */
00946 static VALUE
00947 path_world_writable_p(VALUE self)
00948 {
00949     return rb_funcall(rb_mFileTest, rb_intern("world_writable?"), 1, get_strpath(self));
00950 }
00951 
00952 /*
00953  * See FileTest.writable_real?.
00954  */
00955 static VALUE
00956 path_writable_real_p(VALUE self)
00957 {
00958     return rb_funcall(rb_mFileTest, rb_intern("writable_real?"), 1, get_strpath(self));
00959 }
00960 
00961 /*
00962  * See FileTest.zero?.
00963  */
00964 static VALUE
00965 path_zero_p(VALUE self)
00966 {
00967     return rb_funcall(rb_mFileTest, rb_intern("zero?"), 1, get_strpath(self));
00968 }
00969 
00970 static VALUE
00971 glob_i(RB_BLOCK_CALL_FUNC_ARGLIST(elt, klass))
00972 {
00973     return rb_yield(rb_class_new_instance(1, &elt, klass));
00974 }
00975 
00976 /*
00977  * Returns or yields Pathname objects.
00978  *
00979  *  Pathname.glob("config/" "*.rb")
00980  *      #=> [#<Pathname:config/environment.rb>, #<Pathname:config/routes.rb>, ..]
00981  *
00982  * See Dir.glob.
00983  */
00984 static VALUE
00985 path_s_glob(int argc, VALUE *argv, VALUE klass)
00986 {
00987     VALUE args[2];
00988     int n;
00989 
00990     n = rb_scan_args(argc, argv, "11", &args[0], &args[1]);
00991     if (rb_block_given_p()) {
00992         return rb_block_call(rb_cDir, rb_intern("glob"), n, args, glob_i, klass);
00993     }
00994     else {
00995         VALUE ary;
00996         long i;
00997         ary = rb_funcall2(rb_cDir, rb_intern("glob"), n, args);
00998         ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
00999         for (i = 0; i < RARRAY_LEN(ary); i++) {
01000             VALUE elt = RARRAY_AREF(ary, i);
01001             elt = rb_class_new_instance(1, &elt, klass);
01002             rb_ary_store(ary, i, elt);
01003         }
01004         return ary;
01005     }
01006 }
01007 
01008 /*
01009  * Returns the current working directory as a Pathname.
01010  *
01011  *      Pathname.getwd
01012  *          #=> #<Pathname:/home/zzak/projects/ruby>
01013  *
01014  * See Dir.getwd.
01015  */
01016 static VALUE
01017 path_s_getwd(VALUE klass)
01018 {
01019     VALUE str;
01020     str = rb_funcall(rb_cDir, rb_intern("getwd"), 0);
01021     return rb_class_new_instance(1, &str, klass);
01022 }
01023 
01024 /*
01025  * Return the entries (files and subdirectories) in the directory, each as a
01026  * Pathname object.
01027  *
01028  * The results contains just the names in the directory, without any trailing
01029  * slashes or recursive look-up.
01030  *
01031  *   pp Pathname.new('/usr/local').entries
01032  *   #=> [#<Pathname:share>,
01033  *   #    #<Pathname:lib>,
01034  *   #    #<Pathname:..>,
01035  *   #    #<Pathname:include>,
01036  *   #    #<Pathname:etc>,
01037  *   #    #<Pathname:bin>,
01038  *   #    #<Pathname:man>,
01039  *   #    #<Pathname:games>,
01040  *   #    #<Pathname:.>,
01041  *   #    #<Pathname:sbin>,
01042  *   #    #<Pathname:src>]
01043  *
01044  * The result may contain the current directory <code>#<Pathname:.></code> and
01045  * the parent directory <code>#<Pathname:..></code>.
01046  *
01047  * If you don't want +.+ and +..+ and
01048  * want directories, consider Pathname#children.
01049  */
01050 static VALUE
01051 path_entries(VALUE self)
01052 {
01053     VALUE klass, str, ary;
01054     long i;
01055     klass = rb_obj_class(self);
01056     str = get_strpath(self);
01057     ary = rb_funcall(rb_cDir, rb_intern("entries"), 1, str);
01058     ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
01059     for (i = 0; i < RARRAY_LEN(ary); i++) {
01060         VALUE elt = RARRAY_AREF(ary, i);
01061         elt = rb_class_new_instance(1, &elt, klass);
01062         rb_ary_store(ary, i, elt);
01063     }
01064     return ary;
01065 }
01066 
01067 /*
01068  * Create the referenced directory.
01069  *
01070  * See Dir.mkdir.
01071  */
01072 static VALUE
01073 path_mkdir(int argc, VALUE *argv, VALUE self)
01074 {
01075     VALUE str = get_strpath(self);
01076     VALUE vmode;
01077     if (rb_scan_args(argc, argv, "01", &vmode) == 0)
01078         return rb_funcall(rb_cDir, rb_intern("mkdir"), 1, str);
01079     else
01080         return rb_funcall(rb_cDir, rb_intern("mkdir"), 2, str, vmode);
01081 }
01082 
01083 /*
01084  * Remove the referenced directory.
01085  *
01086  * See Dir.rmdir.
01087  */
01088 static VALUE
01089 path_rmdir(VALUE self)
01090 {
01091     return rb_funcall(rb_cDir, rb_intern("rmdir"), 1, get_strpath(self));
01092 }
01093 
01094 /*
01095  * Opens the referenced directory.
01096  *
01097  * See Dir.open.
01098  */
01099 static VALUE
01100 path_opendir(VALUE self)
01101 {
01102     VALUE args[1];
01103 
01104     args[0] = get_strpath(self);
01105     return rb_block_call(rb_cDir, rb_intern("open"), 1, args, 0, 0);
01106 }
01107 
01108 static VALUE
01109 each_entry_i(RB_BLOCK_CALL_FUNC_ARGLIST(elt, klass))
01110 {
01111     return rb_yield(rb_class_new_instance(1, &elt, klass));
01112 }
01113 
01114 /*
01115  * Iterates over the entries (files and subdirectories) in the directory,
01116  * yielding a Pathname object for each entry.
01117  */
01118 static VALUE
01119 path_each_entry(VALUE self)
01120 {
01121     VALUE args[1];
01122 
01123     args[0] = get_strpath(self);
01124     return rb_block_call(rb_cDir, rb_intern("foreach"), 1, args, each_entry_i, rb_obj_class(self));
01125 }
01126 
01127 static VALUE
01128 unlink_body(VALUE str)
01129 {
01130     return rb_funcall(rb_cDir, rb_intern("unlink"), 1, str);
01131 }
01132 
01133 static VALUE
01134 unlink_rescue(VALUE str, VALUE errinfo)
01135 {
01136     return rb_funcall(rb_cFile, rb_intern("unlink"), 1, str);
01137 }
01138 
01139 /*
01140  * Removes a file or directory, using File.unlink if +self+ is a file, or
01141  * Dir.unlink as necessary.
01142  */
01143 static VALUE
01144 path_unlink(VALUE self)
01145 {
01146     VALUE eENOTDIR = rb_const_get_at(rb_mErrno, rb_intern("ENOTDIR"));
01147     VALUE str = get_strpath(self);
01148     return rb_rescue2(unlink_body, str, unlink_rescue, str, eENOTDIR, (VALUE)0);
01149 }
01150 
01151 /*
01152  * :call-seq:
01153  *  Pathname(path)  -> pathname
01154  *
01155  * Creates a new Pathname object from the given string, +path+, and returns
01156  * pathname object.
01157  *
01158  * In order to use this constructor, you must first require the Pathname
01159  * standard library extension.
01160  *
01161  *      require 'pathname'
01162  *      Pathname("/home/zzak")
01163  *      #=> #<Pathname:/home/zzak>
01164  *
01165  * See also Pathname::new for more information.
01166  */
01167 static VALUE
01168 path_f_pathname(VALUE self, VALUE str)
01169 {
01170     return rb_class_new_instance(1, &str, rb_cPathname);
01171 }
01172 
01173 /*
01174  *
01175  * Pathname represents the name of a file or directory on the filesystem,
01176  * but not the file itself.
01177  *
01178  * The pathname depends on the Operating System: Unix, Windows, etc.
01179  * This library works with pathnames of local OS, however non-Unix pathnames
01180  * are supported experimentally.
01181  *
01182  * A Pathname can be relative or absolute.  It's not until you try to
01183  * reference the file that it even matters whether the file exists or not.
01184  *
01185  * Pathname is immutable.  It has no method for destructive update.
01186  *
01187  * The goal of this class is to manipulate file path information in a neater
01188  * way than standard Ruby provides.  The examples below demonstrate the
01189  * difference.
01190  *
01191  * *All* functionality from File, FileTest, and some from Dir and FileUtils is
01192  * included, in an unsurprising way.  It is essentially a facade for all of
01193  * these, and more.
01194  *
01195  * == Examples
01196  *
01197  * === Example 1: Using Pathname
01198  *
01199  *   require 'pathname'
01200  *   pn = Pathname.new("/usr/bin/ruby")
01201  *   size = pn.size              # 27662
01202  *   isdir = pn.directory?       # false
01203  *   dir  = pn.dirname           # Pathname:/usr/bin
01204  *   base = pn.basename          # Pathname:ruby
01205  *   dir, base = pn.split        # [Pathname:/usr/bin, Pathname:ruby]
01206  *   data = pn.read
01207  *   pn.open { |f| _ }
01208  *   pn.each_line { |line| _ }
01209  *
01210  * === Example 2: Using standard Ruby
01211  *
01212  *   pn = "/usr/bin/ruby"
01213  *   size = File.size(pn)        # 27662
01214  *   isdir = File.directory?(pn) # false
01215  *   dir  = File.dirname(pn)     # "/usr/bin"
01216  *   base = File.basename(pn)    # "ruby"
01217  *   dir, base = File.split(pn)  # ["/usr/bin", "ruby"]
01218  *   data = File.read(pn)
01219  *   File.open(pn) { |f| _ }
01220  *   File.foreach(pn) { |line| _ }
01221  *
01222  * === Example 3: Special features
01223  *
01224  *   p1 = Pathname.new("/usr/lib")   # Pathname:/usr/lib
01225  *   p2 = p1 + "ruby/1.8"            # Pathname:/usr/lib/ruby/1.8
01226  *   p3 = p1.parent                  # Pathname:/usr
01227  *   p4 = p2.relative_path_from(p3)  # Pathname:lib/ruby/1.8
01228  *   pwd = Pathname.pwd              # Pathname:/home/gavin
01229  *   pwd.absolute?                   # true
01230  *   p5 = Pathname.new "."           # Pathname:.
01231  *   p5 = p5 + "music/../articles"   # Pathname:music/../articles
01232  *   p5.cleanpath                    # Pathname:articles
01233  *   p5.realpath                     # Pathname:/home/gavin/articles
01234  *   p5.children                     # [Pathname:/home/gavin/articles/linux, ...]
01235  *
01236  * == Breakdown of functionality
01237  *
01238  * === Core methods
01239  *
01240  * These methods are effectively manipulating a String, because that's
01241  * all a path is.  None of these access the file system except for
01242  * #mountpoint?, #children, #each_child, #realdirpath and #realpath.
01243  *
01244  * - +
01245  * - #join
01246  * - #parent
01247  * - #root?
01248  * - #absolute?
01249  * - #relative?
01250  * - #relative_path_from
01251  * - #each_filename
01252  * - #cleanpath
01253  * - #realpath
01254  * - #realdirpath
01255  * - #children
01256  * - #each_child
01257  * - #mountpoint?
01258  *
01259  * === File status predicate methods
01260  *
01261  * These methods are a facade for FileTest:
01262  * - #blockdev?
01263  * - #chardev?
01264  * - #directory?
01265  * - #executable?
01266  * - #executable_real?
01267  * - #exist?
01268  * - #file?
01269  * - #grpowned?
01270  * - #owned?
01271  * - #pipe?
01272  * - #readable?
01273  * - #world_readable?
01274  * - #readable_real?
01275  * - #setgid?
01276  * - #setuid?
01277  * - #size
01278  * - #size?
01279  * - #socket?
01280  * - #sticky?
01281  * - #symlink?
01282  * - #writable?
01283  * - #world_writable?
01284  * - #writable_real?
01285  * - #zero?
01286  *
01287  * === File property and manipulation methods
01288  *
01289  * These methods are a facade for File:
01290  * - #atime
01291  * - #ctime
01292  * - #mtime
01293  * - #chmod(mode)
01294  * - #lchmod(mode)
01295  * - #chown(owner, group)
01296  * - #lchown(owner, group)
01297  * - #fnmatch(pattern, *args)
01298  * - #fnmatch?(pattern, *args)
01299  * - #ftype
01300  * - #make_link(old)
01301  * - #open(*args, &block)
01302  * - #readlink
01303  * - #rename(to)
01304  * - #stat
01305  * - #lstat
01306  * - #make_symlink(old)
01307  * - #truncate(length)
01308  * - #utime(atime, mtime)
01309  * - #basename(*args)
01310  * - #dirname
01311  * - #extname
01312  * - #expand_path(*args)
01313  * - #split
01314  *
01315  * === Directory methods
01316  *
01317  * These methods are a facade for Dir:
01318  * - Pathname.glob(*args)
01319  * - Pathname.getwd / Pathname.pwd
01320  * - #rmdir
01321  * - #entries
01322  * - #each_entry(&block)
01323  * - #mkdir(*args)
01324  * - #opendir(*args)
01325  *
01326  * === IO
01327  *
01328  * These methods are a facade for IO:
01329  * - #each_line(*args, &block)
01330  * - #read(*args)
01331  * - #binread(*args)
01332  * - #readlines(*args)
01333  * - #sysopen(*args)
01334  *
01335  * === Utilities
01336  *
01337  * These methods are a mixture of Find, FileUtils, and others:
01338  * - #find(&block)
01339  * - #mkpath
01340  * - #rmtree
01341  * - #unlink / #delete
01342  *
01343  *
01344  * == Method documentation
01345  *
01346  * As the above section shows, most of the methods in Pathname are facades.  The
01347  * documentation for these methods generally just says, for instance, "See
01348  * FileTest.writable?", as you should be familiar with the original method
01349  * anyway, and its documentation (e.g. through +ri+) will contain more
01350  * information.  In some cases, a brief description will follow.
01351  */
01352 void
01353 Init_pathname()
01354 {
01355     id_at_path = rb_intern("@path");
01356     id_to_path = rb_intern("to_path");
01357 
01358     rb_cPathname = rb_define_class("Pathname", rb_cObject);
01359     rb_define_method(rb_cPathname, "initialize", path_initialize, 1);
01360     rb_define_method(rb_cPathname, "freeze", path_freeze, 0);
01361     rb_define_method(rb_cPathname, "taint", path_taint, 0);
01362     rb_define_method(rb_cPathname, "untaint", path_untaint, 0);
01363     rb_define_method(rb_cPathname, "==", path_eq, 1);
01364     rb_define_method(rb_cPathname, "===", path_eq, 1);
01365     rb_define_method(rb_cPathname, "eql?", path_eq, 1);
01366     rb_define_method(rb_cPathname, "<=>", path_cmp, 1);
01367     rb_define_method(rb_cPathname, "hash", path_hash, 0);
01368     rb_define_method(rb_cPathname, "to_s", path_to_s, 0);
01369     rb_define_method(rb_cPathname, "to_path", path_to_s, 0);
01370     rb_define_method(rb_cPathname, "inspect", path_inspect, 0);
01371     rb_define_method(rb_cPathname, "sub", path_sub, -1);
01372     rb_define_method(rb_cPathname, "sub_ext", path_sub_ext, 1);
01373     rb_define_method(rb_cPathname, "realpath", path_realpath, -1);
01374     rb_define_method(rb_cPathname, "realdirpath", path_realdirpath, -1);
01375     rb_define_method(rb_cPathname, "each_line", path_each_line, -1);
01376     rb_define_method(rb_cPathname, "read", path_read, -1);
01377     rb_define_method(rb_cPathname, "binread", path_binread, -1);
01378     rb_define_method(rb_cPathname, "readlines", path_readlines, -1);
01379     rb_define_method(rb_cPathname, "write", path_write, -1);
01380     rb_define_method(rb_cPathname, "binwrite", path_binwrite, -1);
01381     rb_define_method(rb_cPathname, "sysopen", path_sysopen, -1);
01382     rb_define_method(rb_cPathname, "atime", path_atime, 0);
01383     rb_define_method(rb_cPathname, "ctime", path_ctime, 0);
01384     rb_define_method(rb_cPathname, "mtime", path_mtime, 0);
01385     rb_define_method(rb_cPathname, "chmod", path_chmod, 1);
01386     rb_define_method(rb_cPathname, "lchmod", path_lchmod, 1);
01387     rb_define_method(rb_cPathname, "chown", path_chown, 2);
01388     rb_define_method(rb_cPathname, "lchown", path_lchown, 2);
01389     rb_define_method(rb_cPathname, "fnmatch", path_fnmatch, -1);
01390     rb_define_method(rb_cPathname, "fnmatch?", path_fnmatch, -1);
01391     rb_define_method(rb_cPathname, "ftype", path_ftype, 0);
01392     rb_define_method(rb_cPathname, "make_link", path_make_link, 1);
01393     rb_define_method(rb_cPathname, "open", path_open, -1);
01394     rb_define_method(rb_cPathname, "readlink", path_readlink, 0);
01395     rb_define_method(rb_cPathname, "rename", path_rename, 1);
01396     rb_define_method(rb_cPathname, "stat", path_stat, 0);
01397     rb_define_method(rb_cPathname, "lstat", path_lstat, 0);
01398     rb_define_method(rb_cPathname, "make_symlink", path_make_symlink, 1);
01399     rb_define_method(rb_cPathname, "truncate", path_truncate, 1);
01400     rb_define_method(rb_cPathname, "utime", path_utime, 2);
01401     rb_define_method(rb_cPathname, "basename", path_basename, -1);
01402     rb_define_method(rb_cPathname, "dirname", path_dirname, 0);
01403     rb_define_method(rb_cPathname, "extname", path_extname, 0);
01404     rb_define_method(rb_cPathname, "expand_path", path_expand_path, -1);
01405     rb_define_method(rb_cPathname, "split", path_split, 0);
01406     rb_define_method(rb_cPathname, "blockdev?", path_blockdev_p, 0);
01407     rb_define_method(rb_cPathname, "chardev?", path_chardev_p, 0);
01408     rb_define_method(rb_cPathname, "executable?", path_executable_p, 0);
01409     rb_define_method(rb_cPathname, "executable_real?", path_executable_real_p, 0);
01410     rb_define_method(rb_cPathname, "exist?", path_exist_p, 0);
01411     rb_define_method(rb_cPathname, "grpowned?", path_grpowned_p, 0);
01412     rb_define_method(rb_cPathname, "directory?", path_directory_p, 0);
01413     rb_define_method(rb_cPathname, "file?", path_file_p, 0);
01414     rb_define_method(rb_cPathname, "pipe?", path_pipe_p, 0);
01415     rb_define_method(rb_cPathname, "socket?", path_socket_p, 0);
01416     rb_define_method(rb_cPathname, "owned?", path_owned_p, 0);
01417     rb_define_method(rb_cPathname, "readable?", path_readable_p, 0);
01418     rb_define_method(rb_cPathname, "world_readable?", path_world_readable_p, 0);
01419     rb_define_method(rb_cPathname, "readable_real?", path_readable_real_p, 0);
01420     rb_define_method(rb_cPathname, "setuid?", path_setuid_p, 0);
01421     rb_define_method(rb_cPathname, "setgid?", path_setgid_p, 0);
01422     rb_define_method(rb_cPathname, "size", path_size, 0);
01423     rb_define_method(rb_cPathname, "size?", path_size_p, 0);
01424     rb_define_method(rb_cPathname, "sticky?", path_sticky_p, 0);
01425     rb_define_method(rb_cPathname, "symlink?", path_symlink_p, 0);
01426     rb_define_method(rb_cPathname, "writable?", path_writable_p, 0);
01427     rb_define_method(rb_cPathname, "world_writable?", path_world_writable_p, 0);
01428     rb_define_method(rb_cPathname, "writable_real?", path_writable_real_p, 0);
01429     rb_define_method(rb_cPathname, "zero?", path_zero_p, 0);
01430     rb_define_singleton_method(rb_cPathname, "glob", path_s_glob, -1);
01431     rb_define_singleton_method(rb_cPathname, "getwd", path_s_getwd, 0);
01432     rb_define_singleton_method(rb_cPathname, "pwd", path_s_getwd, 0);
01433     rb_define_method(rb_cPathname, "entries", path_entries, 0);
01434     rb_define_method(rb_cPathname, "mkdir", path_mkdir, -1);
01435     rb_define_method(rb_cPathname, "rmdir", path_rmdir, 0);
01436     rb_define_method(rb_cPathname, "opendir", path_opendir, 0);
01437     rb_define_method(rb_cPathname, "each_entry", path_each_entry, 0);
01438     rb_define_method(rb_cPathname, "unlink", path_unlink, 0);
01439     rb_define_method(rb_cPathname, "delete", path_unlink, 0);
01440     rb_undef_method(rb_cPathname, "=~");
01441     rb_define_global_function("Pathname", path_f_pathname, 1);
01442 }
01443 

Generated on 19 Jul 2016 for Ruby by  doxygen 1.4.7