Ruby  2.1.10p492(2016-04-01revision54464)
pathname.c
Go to the documentation of this file.
1 #include "ruby.h"
2 #include "ruby/encoding.h"
3 
6 
7 static VALUE
9 {
10  VALUE strpath;
11  strpath = rb_ivar_get(obj, id_at_path);
12  if (!RB_TYPE_P(strpath, T_STRING))
13  rb_raise(rb_eTypeError, "unexpected @path");
14  return strpath;
15 }
16 
17 static void
19 {
20  rb_ivar_set(obj, id_at_path, val);
21 }
22 
23 /*
24  * Create a Pathname object from the given String (or String-like object).
25  * If +path+ contains a NULL character (<tt>\0</tt>), an ArgumentError is raised.
26  */
27 static VALUE
29 {
30  VALUE str;
31  if (RB_TYPE_P(arg, T_STRING)) {
32  str = arg;
33  }
34  else {
35  str = rb_check_funcall(arg, id_to_path, 0, NULL);
36  if (str == Qundef)
37  str = arg;
38  StringValue(str);
39  }
40  if (memchr(RSTRING_PTR(str), '\0', RSTRING_LEN(str)))
41  rb_raise(rb_eArgError, "pathname contains null byte");
42  str = rb_obj_dup(str);
43 
44  set_strpath(self, str);
45  OBJ_INFECT(self, str);
46  return self;
47 }
48 
49 /*
50  * call-seq:
51  * pathname.freeze -> obj
52  *
53  * Freezes this Pathname.
54  *
55  * See Object.freeze.
56  */
57 static VALUE
59 {
60  rb_call_super(0, 0);
62  return self;
63 }
64 
65 /*
66  * call-seq:
67  * pathname.taint -> obj
68  *
69  * Taints this Pathname.
70  *
71  * See Object.taint.
72  */
73 static VALUE
75 {
76  rb_call_super(0, 0);
78  return self;
79 }
80 
81 /*
82  * call-seq:
83  * pathname.untaint -> obj
84  *
85  * Untaints this Pathname.
86  *
87  * See Object.untaint.
88  */
89 static VALUE
91 {
92  rb_call_super(0, 0);
94  return self;
95 }
96 
97 /*
98  * Compare this pathname with +other+. The comparison is string-based.
99  * Be aware that two different paths (<tt>foo.txt</tt> and <tt>./foo.txt</tt>)
100  * can refer to the same file.
101  */
102 static VALUE
103 path_eq(VALUE self, VALUE other)
104 {
105  if (!rb_obj_is_kind_of(other, rb_cPathname))
106  return Qfalse;
107  return rb_str_equal(get_strpath(self), get_strpath(other));
108 }
109 
110 /*
111  * Provides a case-sensitive comparison operator for pathnames.
112  *
113  * Pathname.new('/usr') <=> Pathname.new('/usr/bin')
114  * #=> -1
115  * Pathname.new('/usr/bin') <=> Pathname.new('/usr/bin')
116  * #=> 0
117  * Pathname.new('/usr/bin') <=> Pathname.new('/USR/BIN')
118  * #=> 1
119  *
120  * It will return +-1+, +0+ or +1+ depending on the value of the left argument
121  * relative to the right argument. Or it will return +nil+ if the arguments
122  * are not comparable.
123  */
124 static VALUE
125 path_cmp(VALUE self, VALUE other)
126 {
127  VALUE s1, s2;
128  char *p1, *p2;
129  char *e1, *e2;
130  if (!rb_obj_is_kind_of(other, rb_cPathname))
131  return Qnil;
132  s1 = get_strpath(self);
133  s2 = get_strpath(other);
134  p1 = RSTRING_PTR(s1);
135  p2 = RSTRING_PTR(s2);
136  e1 = p1 + RSTRING_LEN(s1);
137  e2 = p2 + RSTRING_LEN(s2);
138  while (p1 < e1 && p2 < e2) {
139  int c1, c2;
140  c1 = (unsigned char)*p1++;
141  c2 = (unsigned char)*p2++;
142  if (c1 == '/') c1 = '\0';
143  if (c2 == '/') c2 = '\0';
144  if (c1 != c2) {
145  if (c1 < c2)
146  return INT2FIX(-1);
147  else
148  return INT2FIX(1);
149  }
150  }
151  if (p1 < e1)
152  return INT2FIX(1);
153  if (p2 < e2)
154  return INT2FIX(-1);
155  return INT2FIX(0);
156 }
157 
158 /* :nodoc: */
159 static VALUE
161 {
162  return INT2FIX(rb_str_hash(get_strpath(self)));
163 }
164 
165 /*
166  * call-seq:
167  * pathname.to_s -> string
168  * pathname.to_path -> string
169  *
170  * Return the path as a String.
171  *
172  * to_path is implemented so Pathname objects are usable with File.open, etc.
173  */
174 static VALUE
176 {
177  return rb_obj_dup(get_strpath(self));
178 }
179 
180 /* :nodoc: */
181 static VALUE
183 {
184  const char *c = rb_obj_classname(self);
185  VALUE str = get_strpath(self);
186  return rb_sprintf("#<%s:%"PRIsVALUE">", c, str);
187 }
188 
189 /*
190  * Return a pathname which is substituted by String#sub.
191  *
192  * path1 = Pathname.new('/usr/bin/perl')
193  * path1.sub('perl', 'ruby')
194  * #=> #<Pathname:/usr/bin/ruby>
195  */
196 static VALUE
198 {
199  VALUE str = get_strpath(self);
200 
201  if (rb_block_given_p()) {
202  str = rb_block_call(str, rb_intern("sub"), argc, argv, 0, 0);
203  }
204  else {
205  str = rb_funcall2(str, rb_intern("sub"), argc, argv);
206  }
207  return rb_class_new_instance(1, &str, rb_obj_class(self));
208 }
209 
210 /*
211  * Return a pathname with +repl+ added as a suffix to the basename.
212  *
213  * If self has no extension part, +repl+ is appended.
214  *
215  * Pathname.new('/usr/bin/shutdown').sub_ext('.rb')
216  * #=> #<Pathname:/usr/bin/shutdown.rb>
217  */
218 static VALUE
220 {
221  VALUE str = get_strpath(self);
222  VALUE str2;
223  long extlen;
224  const char *ext;
225  const char *p;
226 
227  StringValue(repl);
228  p = RSTRING_PTR(str);
229  extlen = RSTRING_LEN(str);
230  ext = ruby_enc_find_extname(p, &extlen, rb_enc_get(str));
231  if (ext == NULL) {
232  ext = p + RSTRING_LEN(str);
233  }
234  else if (extlen <= 1) {
235  ext += extlen;
236  }
237  str2 = rb_str_subseq(str, 0, ext-p);
238  rb_str_append(str2, repl);
239  OBJ_INFECT(str2, str);
240  return rb_class_new_instance(1, &str2, rb_obj_class(self));
241 }
242 
243 /* Facade for File */
244 
245 /*
246  * Returns the real (absolute) pathname for +self+ in the actual
247  * filesystem.
248  *
249  * Does not contain symlinks or useless dots, +..+ and +.+.
250  *
251  * All components of the pathname must exist when this method is
252  * called.
253  *
254  */
255 static VALUE
257 {
258  VALUE basedir, str;
259  rb_scan_args(argc, argv, "01", &basedir);
260  str = rb_funcall(rb_cFile, rb_intern("realpath"), 2, get_strpath(self), basedir);
261  return rb_class_new_instance(1, &str, rb_obj_class(self));
262 }
263 
264 /*
265  * Returns the real (absolute) pathname of +self+ in the actual filesystem.
266  *
267  * Does not contain symlinks or useless dots, +..+ and +.+.
268  *
269  * The last component of the real pathname can be nonexistent.
270  */
271 static VALUE
273 {
274  VALUE basedir, str;
275  rb_scan_args(argc, argv, "01", &basedir);
276  str = rb_funcall(rb_cFile, rb_intern("realdirpath"), 2, get_strpath(self), basedir);
277  return rb_class_new_instance(1, &str, rb_obj_class(self));
278 }
279 
280 /*
281  * call-seq:
282  * pathname.each_line {|line| ... }
283  * pathname.each_line(sep=$/ [, open_args]) {|line| block } -> nil
284  * pathname.each_line(limit [, open_args]) {|line| block } -> nil
285  * pathname.each_line(sep, limit [, open_args]) {|line| block } -> nil
286  * pathname.each_line(...) -> an_enumerator
287  *
288  * Iterates over each line in the file and yields a String object for each.
289  */
290 static VALUE
292 {
293  VALUE args[4];
294  int n;
295 
296  args[0] = get_strpath(self);
297  n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
298  if (rb_block_given_p()) {
299  return rb_block_call(rb_cIO, rb_intern("foreach"), 1+n, args, 0, 0);
300  }
301  else {
302  return rb_funcall2(rb_cIO, rb_intern("foreach"), 1+n, args);
303  }
304 }
305 
306 /*
307  * call-seq:
308  * pathname.read([length [, offset]]) -> string
309  * pathname.read([length [, offset]], open_args) -> string
310  *
311  * Returns all data from the file, or the first +N+ bytes if specified.
312  *
313  * See IO.read.
314  *
315  */
316 static VALUE
318 {
319  VALUE args[4];
320  int n;
321 
322  args[0] = get_strpath(self);
323  n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
324  return rb_funcall2(rb_cIO, rb_intern("read"), 1+n, args);
325 }
326 
327 /*
328  * call-seq:
329  * pathname.binread([length [, offset]]) -> string
330  *
331  * Returns all the bytes from the file, or the first +N+ if specified.
332  *
333  * See IO.binread.
334  *
335  */
336 static VALUE
338 {
339  VALUE args[3];
340  int n;
341 
342  args[0] = get_strpath(self);
343  n = rb_scan_args(argc, argv, "02", &args[1], &args[2]);
344  return rb_funcall2(rb_cIO, rb_intern("binread"), 1+n, args);
345 }
346 
347 /*
348  * call-seq:
349  * pathname.write(string, [offset] ) => fixnum
350  * pathname.write(string, [offset], open_args ) => fixnum
351  *
352  * Writes +contents+ to the file.
353  *
354  * See IO.write.
355  *
356  */
357 static VALUE
359 {
360  VALUE args[4];
361  int n;
362 
363  args[0] = get_strpath(self);
364  n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
365  return rb_funcall2(rb_cIO, rb_intern("write"), 1+n, args);
366 }
367 
368 /*
369  * call-seq:
370  * pathname.binwrite(string, [offset] ) => fixnum
371  * pathname.binwrite(string, [offset], open_args ) => fixnum
372  *
373  * Writes +contents+ to the file, opening it in binary mode.
374  *
375  * See IO.binwrite.
376  *
377  */
378 static VALUE
380 {
381  VALUE args[4];
382  int n;
383 
384  args[0] = get_strpath(self);
385  n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
386  return rb_funcall2(rb_cIO, rb_intern("binwrite"), 1+n, args);
387 }
388 
389 /*
390  * call-seq:
391  * pathname.readlines(sep=$/ [, open_args]) -> array
392  * pathname.readlines(limit [, open_args]) -> array
393  * pathname.readlines(sep, limit [, open_args]) -> array
394  *
395  * Returns all the lines from the file.
396  *
397  * See IO.readlines.
398  *
399  */
400 static VALUE
402 {
403  VALUE args[4];
404  int n;
405 
406  args[0] = get_strpath(self);
407  n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
408  return rb_funcall2(rb_cIO, rb_intern("readlines"), 1+n, args);
409 }
410 
411 /*
412  * call-seq:
413  * pathname.sysopen([mode, [perm]]) -> fixnum
414  *
415  * See IO.sysopen.
416  *
417  */
418 static VALUE
420 {
421  VALUE args[3];
422  int n;
423 
424  args[0] = get_strpath(self);
425  n = rb_scan_args(argc, argv, "02", &args[1], &args[2]);
426  return rb_funcall2(rb_cIO, rb_intern("sysopen"), 1+n, args);
427 }
428 
429 /*
430  * call-seq:
431  * pathname.atime -> time
432  *
433  * Returns the last access time for the file.
434  *
435  * See File.atime.
436  */
437 static VALUE
439 {
440  return rb_funcall(rb_cFile, rb_intern("atime"), 1, get_strpath(self));
441 }
442 
443 /*
444  * call-seq:
445  * pathname.ctime -> time
446  *
447  * Returns the last change time, using directory information, not the file itself.
448  *
449  * See File.ctime.
450  */
451 static VALUE
453 {
454  return rb_funcall(rb_cFile, rb_intern("ctime"), 1, get_strpath(self));
455 }
456 
457 /*
458  * call-seq:
459  * pathname.mtime -> time
460  *
461  * Returns the last modified time of the file.
462  *
463  * See File.mtime.
464  */
465 static VALUE
467 {
468  return rb_funcall(rb_cFile, rb_intern("mtime"), 1, get_strpath(self));
469 }
470 
471 /*
472  * call-seq:
473  * pathname.chmod -> integer
474  *
475  * Changes file permissions.
476  *
477  * See File.chmod.
478  */
479 static VALUE
481 {
482  return rb_funcall(rb_cFile, rb_intern("chmod"), 2, mode, get_strpath(self));
483 }
484 
485 /*
486  * call-seq:
487  * pathname.lchmod -> integer
488  *
489  * Same as Pathname.chmod, but does not follow symbolic links.
490  *
491  * See File.lchmod.
492  */
493 static VALUE
495 {
496  return rb_funcall(rb_cFile, rb_intern("lchmod"), 2, mode, get_strpath(self));
497 }
498 
499 /*
500  * call-seq:
501  * pathname.chown -> integer
502  *
503  * Change owner and group of the file.
504  *
505  * See File.chown.
506  */
507 static VALUE
509 {
510  return rb_funcall(rb_cFile, rb_intern("chown"), 3, owner, group, get_strpath(self));
511 }
512 
513 /*
514  * call-seq:
515  * pathname.lchown -> integer
516  *
517  * Same as Pathname.chown, but does not follow symbolic links.
518  *
519  * See File.lchown.
520  */
521 static VALUE
523 {
524  return rb_funcall(rb_cFile, rb_intern("lchown"), 3, owner, group, get_strpath(self));
525 }
526 
527 /*
528  * call-seq:
529  * pathname.fnmatch(pattern, [flags]) -> string
530  * pathname.fnmatch?(pattern, [flags]) -> string
531  *
532  * Return +true+ if the receiver matches the given pattern.
533  *
534  * See File.fnmatch.
535  */
536 static VALUE
538 {
539  VALUE str = get_strpath(self);
540  VALUE pattern, flags;
541  if (rb_scan_args(argc, argv, "11", &pattern, &flags) == 1)
542  return rb_funcall(rb_cFile, rb_intern("fnmatch"), 2, pattern, str);
543  else
544  return rb_funcall(rb_cFile, rb_intern("fnmatch"), 3, pattern, str, flags);
545 }
546 
547 /*
548  * call-seq:
549  * pathname.ftype -> string
550  *
551  * Returns "type" of file ("file", "directory", etc).
552  *
553  * See File.ftype.
554  */
555 static VALUE
557 {
558  return rb_funcall(rb_cFile, rb_intern("ftype"), 1, get_strpath(self));
559 }
560 
561 /*
562  * call-seq:
563  * pathname.make_link(old)
564  *
565  * Creates a hard link at _pathname_.
566  *
567  * See File.link.
568  */
569 static VALUE
571 {
572  return rb_funcall(rb_cFile, rb_intern("link"), 2, old, get_strpath(self));
573 }
574 
575 /*
576  * Opens the file for reading or writing.
577  *
578  * See File.open.
579  */
580 static VALUE
582 {
583  VALUE args[4];
584  int n;
585 
586  args[0] = get_strpath(self);
587  n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
588  if (rb_block_given_p()) {
589  return rb_block_call(rb_cFile, rb_intern("open"), 1+n, args, 0, 0);
590  }
591  else {
592  return rb_funcall2(rb_cFile, rb_intern("open"), 1+n, args);
593  }
594 }
595 
596 /*
597  * Read symbolic link.
598  *
599  * See File.readlink.
600  */
601 static VALUE
603 {
604  VALUE str;
605  str = rb_funcall(rb_cFile, rb_intern("readlink"), 1, get_strpath(self));
606  return rb_class_new_instance(1, &str, rb_obj_class(self));
607 }
608 
609 /*
610  * Rename the file.
611  *
612  * See File.rename.
613  */
614 static VALUE
616 {
617  return rb_funcall(rb_cFile, rb_intern("rename"), 2, get_strpath(self), to);
618 }
619 
620 /*
621  * Returns a File::Stat object.
622  *
623  * See File.stat.
624  */
625 static VALUE
627 {
628  return rb_funcall(rb_cFile, rb_intern("stat"), 1, get_strpath(self));
629 }
630 
631 /*
632  * See File.lstat.
633  */
634 static VALUE
636 {
637  return rb_funcall(rb_cFile, rb_intern("lstat"), 1, get_strpath(self));
638 }
639 
640 /*
641  * call-seq:
642  * pathname.make_symlink(old)
643  *
644  * Creates a symbolic link.
645  *
646  * See File.symlink.
647  */
648 static VALUE
650 {
651  return rb_funcall(rb_cFile, rb_intern("symlink"), 2, old, get_strpath(self));
652 }
653 
654 /*
655  * Truncates the file to +length+ bytes.
656  *
657  * See File.truncate.
658  */
659 static VALUE
661 {
662  return rb_funcall(rb_cFile, rb_intern("truncate"), 2, get_strpath(self), length);
663 }
664 
665 /*
666  * Update the access and modification times of the file.
667  *
668  * See File.utime.
669  */
670 static VALUE
672 {
673  return rb_funcall(rb_cFile, rb_intern("utime"), 3, atime, mtime, get_strpath(self));
674 }
675 
676 /*
677  * Returns the last component of the path.
678  *
679  * See File.basename.
680  */
681 static VALUE
683 {
684  VALUE str = get_strpath(self);
685  VALUE fext;
686  if (rb_scan_args(argc, argv, "01", &fext) == 0)
687  str = rb_funcall(rb_cFile, rb_intern("basename"), 1, str);
688  else
689  str = rb_funcall(rb_cFile, rb_intern("basename"), 2, str, fext);
690  return rb_class_new_instance(1, &str, rb_obj_class(self));
691 }
692 
693 /*
694  * Returns all but the last component of the path.
695  *
696  * See File.dirname.
697  */
698 static VALUE
700 {
701  VALUE str = get_strpath(self);
702  str = rb_funcall(rb_cFile, rb_intern("dirname"), 1, str);
703  return rb_class_new_instance(1, &str, rb_obj_class(self));
704 }
705 
706 /*
707  * Returns the file's extension.
708  *
709  * See File.extname.
710  */
711 static VALUE
713 {
714  VALUE str = get_strpath(self);
715  return rb_funcall(rb_cFile, rb_intern("extname"), 1, str);
716 }
717 
718 /*
719  * Returns the absolute path for the file.
720  *
721  * See File.expand_path.
722  */
723 static VALUE
725 {
726  VALUE str = get_strpath(self);
727  VALUE dname;
728  if (rb_scan_args(argc, argv, "01", &dname) == 0)
729  str = rb_funcall(rb_cFile, rb_intern("expand_path"), 1, str);
730  else
731  str = rb_funcall(rb_cFile, rb_intern("expand_path"), 2, str, dname);
732  return rb_class_new_instance(1, &str, rb_obj_class(self));
733 }
734 
735 /*
736  * Returns the #dirname and the #basename in an Array.
737  *
738  * See File.split.
739  */
740 static VALUE
742 {
743  VALUE str = get_strpath(self);
744  VALUE ary, dirname, basename;
745  ary = rb_funcall(rb_cFile, rb_intern("split"), 1, str);
746  ary = rb_check_array_type(ary);
747  dirname = rb_ary_entry(ary, 0);
748  basename = rb_ary_entry(ary, 1);
749  dirname = rb_class_new_instance(1, &dirname, rb_obj_class(self));
750  basename = rb_class_new_instance(1, &basename, rb_obj_class(self));
751  return rb_ary_new3(2, dirname, basename);
752 }
753 
754 /*
755  * See FileTest.blockdev?.
756  */
757 static VALUE
759 {
760  return rb_funcall(rb_mFileTest, rb_intern("blockdev?"), 1, get_strpath(self));
761 }
762 
763 /*
764  * See FileTest.chardev?.
765  */
766 static VALUE
768 {
769  return rb_funcall(rb_mFileTest, rb_intern("chardev?"), 1, get_strpath(self));
770 }
771 
772 /*
773  * See FileTest.executable?.
774  */
775 static VALUE
777 {
778  return rb_funcall(rb_mFileTest, rb_intern("executable?"), 1, get_strpath(self));
779 }
780 
781 /*
782  * See FileTest.executable_real?.
783  */
784 static VALUE
786 {
787  return rb_funcall(rb_mFileTest, rb_intern("executable_real?"), 1, get_strpath(self));
788 }
789 
790 /*
791  * See FileTest.exist?.
792  */
793 static VALUE
795 {
796  return rb_funcall(rb_mFileTest, rb_intern("exist?"), 1, get_strpath(self));
797 }
798 
799 /*
800  * See FileTest.grpowned?.
801  */
802 static VALUE
804 {
805  return rb_funcall(rb_mFileTest, rb_intern("grpowned?"), 1, get_strpath(self));
806 }
807 
808 /*
809  * See FileTest.directory?.
810  */
811 static VALUE
813 {
814  return rb_funcall(rb_mFileTest, rb_intern("directory?"), 1, get_strpath(self));
815 }
816 
817 /*
818  * See FileTest.file?.
819  */
820 static VALUE
822 {
823  return rb_funcall(rb_mFileTest, rb_intern("file?"), 1, get_strpath(self));
824 }
825 
826 /*
827  * See FileTest.pipe?.
828  */
829 static VALUE
831 {
832  return rb_funcall(rb_mFileTest, rb_intern("pipe?"), 1, get_strpath(self));
833 }
834 
835 /*
836  * See FileTest.socket?.
837  */
838 static VALUE
840 {
841  return rb_funcall(rb_mFileTest, rb_intern("socket?"), 1, get_strpath(self));
842 }
843 
844 /*
845  * See FileTest.owned?.
846  */
847 static VALUE
849 {
850  return rb_funcall(rb_mFileTest, rb_intern("owned?"), 1, get_strpath(self));
851 }
852 
853 /*
854  * See FileTest.readable?.
855  */
856 static VALUE
858 {
859  return rb_funcall(rb_mFileTest, rb_intern("readable?"), 1, get_strpath(self));
860 }
861 
862 /*
863  * See FileTest.world_readable?.
864  */
865 static VALUE
867 {
868  return rb_funcall(rb_mFileTest, rb_intern("world_readable?"), 1, get_strpath(self));
869 }
870 
871 /*
872  * See FileTest.readable_real?.
873  */
874 static VALUE
876 {
877  return rb_funcall(rb_mFileTest, rb_intern("readable_real?"), 1, get_strpath(self));
878 }
879 
880 /*
881  * See FileTest.setuid?.
882  */
883 static VALUE
885 {
886  return rb_funcall(rb_mFileTest, rb_intern("setuid?"), 1, get_strpath(self));
887 }
888 
889 /*
890  * See FileTest.setgid?.
891  */
892 static VALUE
894 {
895  return rb_funcall(rb_mFileTest, rb_intern("setgid?"), 1, get_strpath(self));
896 }
897 
898 /*
899  * See FileTest.size.
900  */
901 static VALUE
903 {
904  return rb_funcall(rb_mFileTest, rb_intern("size"), 1, get_strpath(self));
905 }
906 
907 /*
908  * See FileTest.size?.
909  */
910 static VALUE
912 {
913  return rb_funcall(rb_mFileTest, rb_intern("size?"), 1, get_strpath(self));
914 }
915 
916 /*
917  * See FileTest.sticky?.
918  */
919 static VALUE
921 {
922  return rb_funcall(rb_mFileTest, rb_intern("sticky?"), 1, get_strpath(self));
923 }
924 
925 /*
926  * See FileTest.symlink?.
927  */
928 static VALUE
930 {
931  return rb_funcall(rb_mFileTest, rb_intern("symlink?"), 1, get_strpath(self));
932 }
933 
934 /*
935  * See FileTest.writable?.
936  */
937 static VALUE
939 {
940  return rb_funcall(rb_mFileTest, rb_intern("writable?"), 1, get_strpath(self));
941 }
942 
943 /*
944  * See FileTest.world_writable?.
945  */
946 static VALUE
948 {
949  return rb_funcall(rb_mFileTest, rb_intern("world_writable?"), 1, get_strpath(self));
950 }
951 
952 /*
953  * See FileTest.writable_real?.
954  */
955 static VALUE
957 {
958  return rb_funcall(rb_mFileTest, rb_intern("writable_real?"), 1, get_strpath(self));
959 }
960 
961 /*
962  * See FileTest.zero?.
963  */
964 static VALUE
966 {
967  return rb_funcall(rb_mFileTest, rb_intern("zero?"), 1, get_strpath(self));
968 }
969 
970 static VALUE
971 glob_i(RB_BLOCK_CALL_FUNC_ARGLIST(elt, klass))
972 {
973  return rb_yield(rb_class_new_instance(1, &elt, klass));
974 }
975 
976 /*
977  * Returns or yields Pathname objects.
978  *
979  * Pathname.glob("config/" "*.rb")
980  * #=> [#<Pathname:config/environment.rb>, #<Pathname:config/routes.rb>, ..]
981  *
982  * See Dir.glob.
983  */
984 static VALUE
986 {
987  VALUE args[2];
988  int n;
989 
990  n = rb_scan_args(argc, argv, "11", &args[0], &args[1]);
991  if (rb_block_given_p()) {
992  return rb_block_call(rb_cDir, rb_intern("glob"), n, args, glob_i, klass);
993  }
994  else {
995  VALUE ary;
996  long i;
997  ary = rb_funcall2(rb_cDir, rb_intern("glob"), n, args);
998  ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
999  for (i = 0; i < RARRAY_LEN(ary); i++) {
1000  VALUE elt = RARRAY_AREF(ary, i);
1001  elt = rb_class_new_instance(1, &elt, klass);
1002  rb_ary_store(ary, i, elt);
1003  }
1004  return ary;
1005  }
1006 }
1007 
1008 /*
1009  * Returns the current working directory as a Pathname.
1010  *
1011  * Pathname.getwd
1012  * #=> #<Pathname:/home/zzak/projects/ruby>
1013  *
1014  * See Dir.getwd.
1015  */
1016 static VALUE
1018 {
1019  VALUE str;
1020  str = rb_funcall(rb_cDir, rb_intern("getwd"), 0);
1021  return rb_class_new_instance(1, &str, klass);
1022 }
1023 
1024 /*
1025  * Return the entries (files and subdirectories) in the directory, each as a
1026  * Pathname object.
1027  *
1028  * The results contains just the names in the directory, without any trailing
1029  * slashes or recursive look-up.
1030  *
1031  * pp Pathname.new('/usr/local').entries
1032  * #=> [#<Pathname:share>,
1033  * # #<Pathname:lib>,
1034  * # #<Pathname:..>,
1035  * # #<Pathname:include>,
1036  * # #<Pathname:etc>,
1037  * # #<Pathname:bin>,
1038  * # #<Pathname:man>,
1039  * # #<Pathname:games>,
1040  * # #<Pathname:.>,
1041  * # #<Pathname:sbin>,
1042  * # #<Pathname:src>]
1043  *
1044  * The result may contain the current directory <code>#<Pathname:.></code> and
1045  * the parent directory <code>#<Pathname:..></code>.
1046  *
1047  * If you don't want +.+ and +..+ and
1048  * want directories, consider Pathname#children.
1049  */
1050 static VALUE
1052 {
1053  VALUE klass, str, ary;
1054  long i;
1055  klass = rb_obj_class(self);
1056  str = get_strpath(self);
1057  ary = rb_funcall(rb_cDir, rb_intern("entries"), 1, str);
1058  ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
1059  for (i = 0; i < RARRAY_LEN(ary); i++) {
1060  VALUE elt = RARRAY_AREF(ary, i);
1061  elt = rb_class_new_instance(1, &elt, klass);
1062  rb_ary_store(ary, i, elt);
1063  }
1064  return ary;
1065 }
1066 
1067 /*
1068  * Create the referenced directory.
1069  *
1070  * See Dir.mkdir.
1071  */
1072 static VALUE
1074 {
1075  VALUE str = get_strpath(self);
1076  VALUE vmode;
1077  if (rb_scan_args(argc, argv, "01", &vmode) == 0)
1078  return rb_funcall(rb_cDir, rb_intern("mkdir"), 1, str);
1079  else
1080  return rb_funcall(rb_cDir, rb_intern("mkdir"), 2, str, vmode);
1081 }
1082 
1083 /*
1084  * Remove the referenced directory.
1085  *
1086  * See Dir.rmdir.
1087  */
1088 static VALUE
1090 {
1091  return rb_funcall(rb_cDir, rb_intern("rmdir"), 1, get_strpath(self));
1092 }
1093 
1094 /*
1095  * Opens the referenced directory.
1096  *
1097  * See Dir.open.
1098  */
1099 static VALUE
1101 {
1102  VALUE args[1];
1103 
1104  args[0] = get_strpath(self);
1105  return rb_block_call(rb_cDir, rb_intern("open"), 1, args, 0, 0);
1106 }
1107 
1108 static VALUE
1109 each_entry_i(RB_BLOCK_CALL_FUNC_ARGLIST(elt, klass))
1110 {
1111  return rb_yield(rb_class_new_instance(1, &elt, klass));
1112 }
1113 
1114 /*
1115  * Iterates over the entries (files and subdirectories) in the directory,
1116  * yielding a Pathname object for each entry.
1117  */
1118 static VALUE
1120 {
1121  VALUE args[1];
1122 
1123  args[0] = get_strpath(self);
1124  return rb_block_call(rb_cDir, rb_intern("foreach"), 1, args, each_entry_i, rb_obj_class(self));
1125 }
1126 
1127 static VALUE
1129 {
1130  return rb_funcall(rb_cDir, rb_intern("unlink"), 1, str);
1131 }
1132 
1133 static VALUE
1135 {
1136  return rb_funcall(rb_cFile, rb_intern("unlink"), 1, str);
1137 }
1138 
1139 /*
1140  * Removes a file or directory, using File.unlink if +self+ is a file, or
1141  * Dir.unlink as necessary.
1142  */
1143 static VALUE
1145 {
1146  VALUE eENOTDIR = rb_const_get_at(rb_mErrno, rb_intern("ENOTDIR"));
1147  VALUE str = get_strpath(self);
1148  return rb_rescue2(unlink_body, str, unlink_rescue, str, eENOTDIR, (VALUE)0);
1149 }
1150 
1151 /*
1152  * :call-seq:
1153  * Pathname(path) -> pathname
1154  *
1155  * Creates a new Pathname object from the given string, +path+, and returns
1156  * pathname object.
1157  *
1158  * In order to use this constructor, you must first require the Pathname
1159  * standard library extension.
1160  *
1161  * require 'pathname'
1162  * Pathname("/home/zzak")
1163  * #=> #<Pathname:/home/zzak>
1164  *
1165  * See also Pathname::new for more information.
1166  */
1167 static VALUE
1169 {
1170  return rb_class_new_instance(1, &str, rb_cPathname);
1171 }
1172 
1173 /*
1174  *
1175  * Pathname represents the name of a file or directory on the filesystem,
1176  * but not the file itself.
1177  *
1178  * The pathname depends on the Operating System: Unix, Windows, etc.
1179  * This library works with pathnames of local OS, however non-Unix pathnames
1180  * are supported experimentally.
1181  *
1182  * A Pathname can be relative or absolute. It's not until you try to
1183  * reference the file that it even matters whether the file exists or not.
1184  *
1185  * Pathname is immutable. It has no method for destructive update.
1186  *
1187  * The goal of this class is to manipulate file path information in a neater
1188  * way than standard Ruby provides. The examples below demonstrate the
1189  * difference.
1190  *
1191  * *All* functionality from File, FileTest, and some from Dir and FileUtils is
1192  * included, in an unsurprising way. It is essentially a facade for all of
1193  * these, and more.
1194  *
1195  * == Examples
1196  *
1197  * === Example 1: Using Pathname
1198  *
1199  * require 'pathname'
1200  * pn = Pathname.new("/usr/bin/ruby")
1201  * size = pn.size # 27662
1202  * isdir = pn.directory? # false
1203  * dir = pn.dirname # Pathname:/usr/bin
1204  * base = pn.basename # Pathname:ruby
1205  * dir, base = pn.split # [Pathname:/usr/bin, Pathname:ruby]
1206  * data = pn.read
1207  * pn.open { |f| _ }
1208  * pn.each_line { |line| _ }
1209  *
1210  * === Example 2: Using standard Ruby
1211  *
1212  * pn = "/usr/bin/ruby"
1213  * size = File.size(pn) # 27662
1214  * isdir = File.directory?(pn) # false
1215  * dir = File.dirname(pn) # "/usr/bin"
1216  * base = File.basename(pn) # "ruby"
1217  * dir, base = File.split(pn) # ["/usr/bin", "ruby"]
1218  * data = File.read(pn)
1219  * File.open(pn) { |f| _ }
1220  * File.foreach(pn) { |line| _ }
1221  *
1222  * === Example 3: Special features
1223  *
1224  * p1 = Pathname.new("/usr/lib") # Pathname:/usr/lib
1225  * p2 = p1 + "ruby/1.8" # Pathname:/usr/lib/ruby/1.8
1226  * p3 = p1.parent # Pathname:/usr
1227  * p4 = p2.relative_path_from(p3) # Pathname:lib/ruby/1.8
1228  * pwd = Pathname.pwd # Pathname:/home/gavin
1229  * pwd.absolute? # true
1230  * p5 = Pathname.new "." # Pathname:.
1231  * p5 = p5 + "music/../articles" # Pathname:music/../articles
1232  * p5.cleanpath # Pathname:articles
1233  * p5.realpath # Pathname:/home/gavin/articles
1234  * p5.children # [Pathname:/home/gavin/articles/linux, ...]
1235  *
1236  * == Breakdown of functionality
1237  *
1238  * === Core methods
1239  *
1240  * These methods are effectively manipulating a String, because that's
1241  * all a path is. None of these access the file system except for
1242  * #mountpoint?, #children, #each_child, #realdirpath and #realpath.
1243  *
1244  * - +
1245  * - #join
1246  * - #parent
1247  * - #root?
1248  * - #absolute?
1249  * - #relative?
1250  * - #relative_path_from
1251  * - #each_filename
1252  * - #cleanpath
1253  * - #realpath
1254  * - #realdirpath
1255  * - #children
1256  * - #each_child
1257  * - #mountpoint?
1258  *
1259  * === File status predicate methods
1260  *
1261  * These methods are a facade for FileTest:
1262  * - #blockdev?
1263  * - #chardev?
1264  * - #directory?
1265  * - #executable?
1266  * - #executable_real?
1267  * - #exist?
1268  * - #file?
1269  * - #grpowned?
1270  * - #owned?
1271  * - #pipe?
1272  * - #readable?
1273  * - #world_readable?
1274  * - #readable_real?
1275  * - #setgid?
1276  * - #setuid?
1277  * - #size
1278  * - #size?
1279  * - #socket?
1280  * - #sticky?
1281  * - #symlink?
1282  * - #writable?
1283  * - #world_writable?
1284  * - #writable_real?
1285  * - #zero?
1286  *
1287  * === File property and manipulation methods
1288  *
1289  * These methods are a facade for File:
1290  * - #atime
1291  * - #ctime
1292  * - #mtime
1293  * - #chmod(mode)
1294  * - #lchmod(mode)
1295  * - #chown(owner, group)
1296  * - #lchown(owner, group)
1297  * - #fnmatch(pattern, *args)
1298  * - #fnmatch?(pattern, *args)
1299  * - #ftype
1300  * - #make_link(old)
1301  * - #open(*args, &block)
1302  * - #readlink
1303  * - #rename(to)
1304  * - #stat
1305  * - #lstat
1306  * - #make_symlink(old)
1307  * - #truncate(length)
1308  * - #utime(atime, mtime)
1309  * - #basename(*args)
1310  * - #dirname
1311  * - #extname
1312  * - #expand_path(*args)
1313  * - #split
1314  *
1315  * === Directory methods
1316  *
1317  * These methods are a facade for Dir:
1318  * - Pathname.glob(*args)
1319  * - Pathname.getwd / Pathname.pwd
1320  * - #rmdir
1321  * - #entries
1322  * - #each_entry(&block)
1323  * - #mkdir(*args)
1324  * - #opendir(*args)
1325  *
1326  * === IO
1327  *
1328  * These methods are a facade for IO:
1329  * - #each_line(*args, &block)
1330  * - #read(*args)
1331  * - #binread(*args)
1332  * - #readlines(*args)
1333  * - #sysopen(*args)
1334  *
1335  * === Utilities
1336  *
1337  * These methods are a mixture of Find, FileUtils, and others:
1338  * - #find(&block)
1339  * - #mkpath
1340  * - #rmtree
1341  * - #unlink / #delete
1342  *
1343  *
1344  * == Method documentation
1345  *
1346  * As the above section shows, most of the methods in Pathname are facades. The
1347  * documentation for these methods generally just says, for instance, "See
1348  * FileTest.writable?", as you should be familiar with the original method
1349  * anyway, and its documentation (e.g. through +ri+) will contain more
1350  * information. In some cases, a brief description will follow.
1351  */
1352 void
1354 {
1355  id_at_path = rb_intern("@path");
1356  id_to_path = rb_intern("to_path");
1357 
1358  rb_cPathname = rb_define_class("Pathname", rb_cObject);
1359  rb_define_method(rb_cPathname, "initialize", path_initialize, 1);
1360  rb_define_method(rb_cPathname, "freeze", path_freeze, 0);
1362  rb_define_method(rb_cPathname, "untaint", path_untaint, 0);
1365  rb_define_method(rb_cPathname, "eql?", path_eq, 1);
1369  rb_define_method(rb_cPathname, "to_path", path_to_s, 0);
1370  rb_define_method(rb_cPathname, "inspect", path_inspect, 0);
1371  rb_define_method(rb_cPathname, "sub", path_sub, -1);
1372  rb_define_method(rb_cPathname, "sub_ext", path_sub_ext, 1);
1373  rb_define_method(rb_cPathname, "realpath", path_realpath, -1);
1374  rb_define_method(rb_cPathname, "realdirpath", path_realdirpath, -1);
1375  rb_define_method(rb_cPathname, "each_line", path_each_line, -1);
1376  rb_define_method(rb_cPathname, "read", path_read, -1);
1377  rb_define_method(rb_cPathname, "binread", path_binread, -1);
1378  rb_define_method(rb_cPathname, "readlines", path_readlines, -1);
1379  rb_define_method(rb_cPathname, "write", path_write, -1);
1380  rb_define_method(rb_cPathname, "binwrite", path_binwrite, -1);
1381  rb_define_method(rb_cPathname, "sysopen", path_sysopen, -1);
1386  rb_define_method(rb_cPathname, "lchmod", path_lchmod, 1);
1388  rb_define_method(rb_cPathname, "lchown", path_lchown, 2);
1389  rb_define_method(rb_cPathname, "fnmatch", path_fnmatch, -1);
1390  rb_define_method(rb_cPathname, "fnmatch?", path_fnmatch, -1);
1392  rb_define_method(rb_cPathname, "make_link", path_make_link, 1);
1393  rb_define_method(rb_cPathname, "open", path_open, -1);
1394  rb_define_method(rb_cPathname, "readlink", path_readlink, 0);
1395  rb_define_method(rb_cPathname, "rename", path_rename, 1);
1398  rb_define_method(rb_cPathname, "make_symlink", path_make_symlink, 1);
1399  rb_define_method(rb_cPathname, "truncate", path_truncate, 1);
1401  rb_define_method(rb_cPathname, "basename", path_basename, -1);
1402  rb_define_method(rb_cPathname, "dirname", path_dirname, 0);
1403  rb_define_method(rb_cPathname, "extname", path_extname, 0);
1404  rb_define_method(rb_cPathname, "expand_path", path_expand_path, -1);
1406  rb_define_method(rb_cPathname, "blockdev?", path_blockdev_p, 0);
1407  rb_define_method(rb_cPathname, "chardev?", path_chardev_p, 0);
1408  rb_define_method(rb_cPathname, "executable?", path_executable_p, 0);
1409  rb_define_method(rb_cPathname, "executable_real?", path_executable_real_p, 0);
1411  rb_define_method(rb_cPathname, "grpowned?", path_grpowned_p, 0);
1412  rb_define_method(rb_cPathname, "directory?", path_directory_p, 0);
1417  rb_define_method(rb_cPathname, "readable?", path_readable_p, 0);
1418  rb_define_method(rb_cPathname, "world_readable?", path_world_readable_p, 0);
1419  rb_define_method(rb_cPathname, "readable_real?", path_readable_real_p, 0);
1425  rb_define_method(rb_cPathname, "symlink?", path_symlink_p, 0);
1426  rb_define_method(rb_cPathname, "writable?", path_writable_p, 0);
1427  rb_define_method(rb_cPathname, "world_writable?", path_world_writable_p, 0);
1428  rb_define_method(rb_cPathname, "writable_real?", path_writable_real_p, 0);
1433  rb_define_method(rb_cPathname, "entries", path_entries, 0);
1434  rb_define_method(rb_cPathname, "mkdir", path_mkdir, -1);
1436  rb_define_method(rb_cPathname, "opendir", path_opendir, 0);
1437  rb_define_method(rb_cPathname, "each_entry", path_each_entry, 0);
1438  rb_define_method(rb_cPathname, "unlink", path_unlink, 0);
1439  rb_define_method(rb_cPathname, "delete", path_unlink, 0);
1442 }
#define RB_TYPE_P(obj, type)
VALUE rb_const_get_at(VALUE, ID)
Definition: variable.c:1886
static VALUE unlink_rescue(VALUE str, VALUE errinfo)
Definition: pathname.c:1134
rb_funcall2(argv[0], id_yield, argc-1, argv+1)
static VALUE path_world_writable_p(VALUE self)
Definition: pathname.c:947
VALUE rb_ary_entry(VALUE ary, long offset)
Definition: array.c:1179
#define OBJ_INFECT(x, s)
static VALUE path_owned_p(VALUE self)
Definition: pathname.c:848
static VALUE path_zero_p(VALUE self)
Definition: pathname.c:965
VALUE rb_class_new_instance(int, VALUE *, VALUE)
Definition: object.c:1857
const char * rb_obj_classname(VALUE)
Definition: variable.c:406
static VALUE path_mkdir(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:1073
static VALUE path_pipe_p(VALUE self)
Definition: pathname.c:830
static VALUE path_writable_p(VALUE self)
Definition: pathname.c:938
static VALUE path_size(VALUE self)
Definition: pathname.c:902
static VALUE path_rmdir(VALUE self)
Definition: pathname.c:1089
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1646
rb_funcall(memo->yielder, id_lshift, 1, rb_assoc_new(memo->prev_value, memo->prev_elts))
static VALUE path_readable_real_p(VALUE self)
Definition: pathname.c:875
static VALUE path_readable_p(VALUE self)
Definition: pathname.c:857
static VALUE path_executable_real_p(VALUE self)
Definition: pathname.c:785
VALUE rb_str_subseq(VALUE, long, long)
Definition: string.c:1838
static VALUE path_socket_p(VALUE self)
Definition: pathname.c:839
const char * ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc)
Definition: file.c:3966
static VALUE path_atime(VALUE self)
Definition: pathname.c:438
rb_yield(i)
VALUE rb_eTypeError
Definition: error.c:548
VALUE rb_obj_dup(VALUE)
Definition: object.c:406
static VALUE path_each_entry(VALUE self)
Definition: pathname.c:1119
static VALUE path_to_s(VALUE self)
Definition: pathname.c:175
static VALUE get_strpath(VALUE obj)
Definition: pathname.c:8
rb_str_append(str, i)
#define RSTRING_PTR(str)
#define T_ARRAY
static VALUE path_fnmatch(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:537
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1857
group
Definition: enum.c:723
VALUE rb_obj_class(VALUE)
Definition: object.c:226
static VALUE path_chardev_p(VALUE self)
Definition: pathname.c:767
static VALUE path_ctime(VALUE self)
Definition: pathname.c:452
static VALUE path_taint(VALUE self)
Definition: pathname.c:74
static VALUE path_read(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:317
static VALUE path_opendir(VALUE self)
Definition: pathname.c:1100
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1675
static VALUE path_executable_p(VALUE self)
Definition: pathname.c:776
static VALUE path_chmod(VALUE self, VALUE mode)
Definition: pathname.c:480
static VALUE path_f_pathname(VALUE self, VALUE str)
Definition: pathname.c:1168
static VALUE path_s_getwd(VALUE klass)
Definition: pathname.c:1017
void rb_undef_method(VALUE klass, const char *name)
Definition: class.c:1497
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1115
VALUE rb_str_equal(VALUE str1, VALUE str2)
Definition: string.c:2542
i
Definition: enum.c:446
VALUE ary
Definition: enum.c:674
static VALUE path_realdirpath(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:272
static VALUE path_make_link(VALUE self, VALUE old)
Definition: pathname.c:570
static VALUE path_lchmod(VALUE self, VALUE mode)
Definition: pathname.c:494
static VALUE path_truncate(VALUE self, VALUE length)
Definition: pathname.c:660
static VALUE path_sticky_p(VALUE self)
Definition: pathname.c:920
static VALUE path_eq(VALUE self, VALUE other)
Definition: pathname.c:103
RUBY_EXTERN VALUE rb_mFileTest
Definition: ripper.y:1553
return Qfalse
Definition: tcltklib.c:6790
int rb_block_given_p(void)
Definition: eval.c:712
#define RARRAY_LEN(a)
static VALUE unlink_body(VALUE str)
Definition: pathname.c:1128
#define Qnil
Definition: enum.c:67
#define val
Definition: tcltklib.c:1935
static VALUE char * str
Definition: tcltklib.c:3539
static VALUE path_setgid_p(VALUE self)
Definition: pathname.c:893
#define RARRAY_AREF(a, i)
int flags
Definition: tcltklib.c:3015
unsigned long ID
Definition: ripper.y:89
static VALUE path_hash(VALUE self)
Definition: pathname.c:160
static VALUE path_file_p(VALUE self)
Definition: pathname.c:821
static VALUE path_entries(VALUE self)
Definition: pathname.c:1051
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:611
static VALUE VALUE obj
Definition: tcltklib.c:3150
#define RSTRING_LEN(str)
#define INT2FIX(i)
static VALUE path_exist_p(VALUE self)
Definition: pathname.c:794
void rb_ary_store(VALUE ary, long idx, VALUE val)
Definition: array.c:794
#define T_STRING
static VALUE path_readlink(VALUE self)
Definition: pathname.c:602
static VALUE path_binwrite(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:379
static VALUE path_extname(VALUE self)
Definition: pathname.c:712
static VALUE path_unlink(VALUE self)
Definition: pathname.c:1144
static VALUE path_write(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:358
VALUE rb_call_super(int, const VALUE *)
Definition: vm_eval.c:275
VALUE rb_str_freeze(VALUE)
Definition: string.c:1967
static VALUE path_inspect(VALUE self)
Definition: pathname.c:182
VALUE rb_mErrno
Definition: error.c:567
static VALUE path_untaint(VALUE self)
Definition: pathname.c:90
static VALUE rb_cPathname
Definition: pathname.c:4
static VALUE path_dirname(VALUE self)
Definition: pathname.c:699
VALUE arg
Definition: enum.c:2427
static VALUE path_make_symlink(VALUE self, VALUE old)
Definition: pathname.c:649
VALUE * argv
Definition: tcltklib.c:1969
static VALUE path_readlines(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:401
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1250
#define StringValue(v)
rb_block_call(enumerable, id_each, 0, 0, chunk_ii, arg)
static void set_strpath(VALUE obj, VALUE val)
Definition: pathname.c:18
VALUE mode
Definition: tcltklib.c:1668
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1719
static VALUE path_grpowned_p(VALUE self)
Definition: pathname.c:803
size_t length
Definition: tcltklib.c:4549
VALUE rb_cDir
Definition: dir.c:350
static VALUE path_writable_real_p(VALUE self)
Definition: pathname.c:956
VALUE rb_obj_untaint(VALUE)
Definition: object.c:987
static VALUE path_size_p(VALUE self)
Definition: pathname.c:911
int argc
Definition: tcltklib.c:1968
static VALUE path_world_readable_p(VALUE self)
Definition: pathname.c:866
VALUE rb_rescue2(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2,...)
Definition: eval.c:741
static VALUE path_each_line(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:291
static VALUE path_freeze(VALUE self)
Definition: pathname.c:58
VpDivd * c
Definition: bigdecimal.c:1223
RUBY_EXTERN VALUE rb_cIO
Definition: ripper.y:1577
static VALUE path_lchown(VALUE self, VALUE owner, VALUE group)
Definition: pathname.c:522
static VALUE path_ftype(VALUE self)
Definition: pathname.c:556
VALUE rb_obj_taint(VALUE)
Definition: object.c:967
void Init_pathname()
Definition: pathname.c:1353
RUBY_EXTERN VALUE rb_cFile
Definition: ripper.y:1572
static VALUE path_sub(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:197
static VALUE path_lstat(VALUE self)
Definition: pathname.c:635
rb_encoding * rb_enc_get(VALUE obj)
Definition: encoding.c:832
static VALUE path_binread(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:337
#define Qundef
static VALUE path_directory_p(VALUE self)
Definition: pathname.c:812
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Definition: object.c:646
static VALUE path_utime(VALUE self, VALUE atime, VALUE mtime)
Definition: pathname.c:671
static VALUE path_basename(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:682
static VALUE path_blockdev_p(VALUE self)
Definition: pathname.c:758
static VALUE path_split(VALUE self)
Definition: pathname.c:741
VALUE rb_check_array_type(VALUE ary)
Definition: array.c:632
static VALUE path_rename(VALUE self, VALUE to)
Definition: pathname.c:615
args[0]
Definition: enum.c:585
st_index_t rb_str_hash(VALUE)
Definition: string.c:2421
RUBY_EXTERN VALUE rb_cObject
Definition: ripper.y:1561
static ID id_to_path
Definition: pathname.c:5
klass
Definition: tcltklib.c:3496
static VALUE path_open(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:581
static ID id_at_path
Definition: pathname.c:5
static VALUE path_expand_path(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:724
static VALUE path_s_glob(int argc, VALUE *argv, VALUE klass)
Definition: pathname.c:985
static VALUE path_cmp(VALUE self, VALUE other)
Definition: pathname.c:125
static VALUE path_sysopen(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:419
register C_block * p
Definition: crypt.c:309
rb_ivar_set(yielder, id_memo, LONG2NUM(++count))
static VALUE path_sub_ext(VALUE self, VALUE repl)
Definition: pathname.c:219
data n
Definition: enum.c:860
#define rb_ary_new3
static VALUE path_setuid_p(VALUE self)
Definition: pathname.c:884
#define PRIsVALUE
unsigned long VALUE
Definition: ripper.y:88
static VALUE path_symlink_p(VALUE self)
Definition: pathname.c:929
#define rb_intern(str)
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
static VALUE path_stat(VALUE self)
Definition: pathname.c:626
#define NULL
Definition: _sdbm.c:102
static VALUE path_realpath(int argc, VALUE *argv, VALUE self)
Definition: pathname.c:256
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1479
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
Definition: vm_eval.c:410
static VALUE path_mtime(VALUE self)
Definition: pathname.c:466
static VALUE path_initialize(VALUE self, VALUE arg)
Definition: pathname.c:28
VALUE rb_eArgError
Definition: error.c:549
VALUE rb_convert_type(VALUE, int, const char *, const char *)
Definition: object.c:2637
static VALUE path_chown(VALUE self, VALUE owner, VALUE group)
Definition: pathname.c:508
gz mtime
Definition: zlib.c:2265