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