pathname 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,77 +1,8 @@
1
1
  #include "ruby.h"
2
- #include "ruby/encoding.h"
3
2
 
4
3
  static VALUE rb_cPathname;
5
- static ID id_ENOTDIR;
6
4
  static ID id_at_path;
7
- static ID id_atime;
8
- static ID id_base;
9
- static ID id_basename;
10
- static ID id_binread;
11
- static ID id_binwrite;
12
- static ID id_birthtime;
13
- static ID id_blockdev_p;
14
- static ID id_chardev_p;
15
- static ID id_chmod;
16
- static ID id_chown;
17
- static ID id_ctime;
18
- static ID id_directory_p;
19
- static ID id_dirname;
20
- static ID id_empty_p;
21
- static ID id_entries;
22
- static ID id_executable_p;
23
- static ID id_executable_real_p;
24
- static ID id_exist_p;
25
- static ID id_expand_path;
26
- static ID id_extname;
27
- static ID id_file_p;
28
- static ID id_fnmatch;
29
- static ID id_foreach;
30
- static ID id_ftype;
31
- static ID id_getwd;
32
- static ID id_glob;
33
- static ID id_grpowned_p;
34
- static ID id_lchmod;
35
- static ID id_lchown;
36
- static ID id_link;
37
- static ID id_lstat;
38
- static ID id_lutime;
39
- static ID id_mkdir;
40
- static ID id_mtime;
41
- static ID id_open;
42
- static ID id_owned_p;
43
- static ID id_pipe_p;
44
- static ID id_read;
45
- static ID id_readable_p;
46
- static ID id_readable_real_p;
47
- static ID id_readlines;
48
- static ID id_readlink;
49
- static ID id_realdirpath;
50
- static ID id_realpath;
51
- static ID id_rename;
52
- static ID id_rmdir;
53
- static ID id_setgid_p;
54
- static ID id_setuid_p;
55
- static ID id_size;
56
- static ID id_size_p;
57
- static ID id_socket_p;
58
- static ID id_split;
59
- static ID id_stat;
60
- static ID id_sticky_p;
61
5
  static ID id_sub;
62
- static ID id_symlink;
63
- static ID id_symlink_p;
64
- static ID id_sysopen;
65
- static ID id_to_path;
66
- static ID id_truncate;
67
- static ID id_unlink;
68
- static ID id_utime;
69
- static ID id_world_readable_p;
70
- static ID id_world_writable_p;
71
- static ID id_writable_p;
72
- static ID id_writable_real_p;
73
- static ID id_write;
74
- static ID id_zero_p;
75
6
 
76
7
  static VALUE
77
8
  get_strpath(VALUE obj)
@@ -83,66 +14,6 @@ get_strpath(VALUE obj)
83
14
  return strpath;
84
15
  }
85
16
 
86
- static void
87
- set_strpath(VALUE obj, VALUE val)
88
- {
89
- rb_ivar_set(obj, id_at_path, val);
90
- }
91
-
92
- /*
93
- * Create a Pathname object from the given String (or String-like object).
94
- * If +path+ contains a NULL character (<tt>\0</tt>), an ArgumentError is raised.
95
- */
96
- static VALUE
97
- path_initialize(VALUE self, VALUE arg)
98
- {
99
- VALUE str;
100
- if (RB_TYPE_P(arg, T_STRING)) {
101
- str = arg;
102
- }
103
- else {
104
- str = rb_check_funcall(arg, id_to_path, 0, NULL);
105
- if (str == Qundef)
106
- str = arg;
107
- StringValue(str);
108
- }
109
- if (memchr(RSTRING_PTR(str), '\0', RSTRING_LEN(str)))
110
- rb_raise(rb_eArgError, "pathname contains null byte");
111
- str = rb_obj_dup(str);
112
-
113
- set_strpath(self, str);
114
- return self;
115
- }
116
-
117
- /*
118
- * call-seq:
119
- * pathname.freeze -> obj
120
- *
121
- * Freezes this Pathname.
122
- *
123
- * See Object.freeze.
124
- */
125
- static VALUE
126
- path_freeze(VALUE self)
127
- {
128
- rb_call_super(0, 0);
129
- rb_str_freeze(get_strpath(self));
130
- return self;
131
- }
132
-
133
- /*
134
- * Compare this pathname with +other+. The comparison is string-based.
135
- * Be aware that two different paths (<tt>foo.txt</tt> and <tt>./foo.txt</tt>)
136
- * can refer to the same file.
137
- */
138
- static VALUE
139
- path_eq(VALUE self, VALUE other)
140
- {
141
- if (!rb_obj_is_kind_of(other, rb_cPathname))
142
- return Qfalse;
143
- return rb_str_equal(get_strpath(self), get_strpath(other));
144
- }
145
-
146
17
  /*
147
18
  * Provides a case-sensitive comparison operator for pathnames.
148
19
  *
@@ -191,41 +62,6 @@ path_cmp(VALUE self, VALUE other)
191
62
  return INT2FIX(0);
192
63
  }
193
64
 
194
- #ifndef ST2FIX
195
- #define ST2FIX(h) LONG2FIX((long)(h))
196
- #endif
197
-
198
- /* :nodoc: */
199
- static VALUE
200
- path_hash(VALUE self)
201
- {
202
- return ST2FIX(rb_str_hash(get_strpath(self)));
203
- }
204
-
205
- /*
206
- * call-seq:
207
- * pathname.to_s -> string
208
- * pathname.to_path -> string
209
- *
210
- * Return the path as a String.
211
- *
212
- * to_path is implemented so Pathname objects are usable with File.open, etc.
213
- */
214
- static VALUE
215
- path_to_s(VALUE self)
216
- {
217
- return rb_obj_dup(get_strpath(self));
218
- }
219
-
220
- /* :nodoc: */
221
- static VALUE
222
- path_inspect(VALUE self)
223
- {
224
- const char *c = rb_obj_classname(self);
225
- VALUE str = get_strpath(self);
226
- return rb_sprintf("#<%s:%"PRIsVALUE">", c, str);
227
- }
228
-
229
65
  /*
230
66
  * Return a pathname which is substituted by String#sub.
231
67
  *
@@ -247,1422 +83,31 @@ path_sub(int argc, VALUE *argv, VALUE self)
247
83
  return rb_class_new_instance(1, &str, rb_obj_class(self));
248
84
  }
249
85
 
250
- /*
251
- * Return a pathname with +repl+ added as a suffix to the basename.
252
- *
253
- * If self has no extension part, +repl+ is appended.
254
- *
255
- * Pathname.new('/usr/bin/shutdown').sub_ext('.rb')
256
- * #=> #<Pathname:/usr/bin/shutdown.rb>
257
- */
258
- static VALUE
259
- path_sub_ext(VALUE self, VALUE repl)
260
- {
261
- VALUE str = get_strpath(self);
262
- VALUE str2;
263
- long extlen;
264
- const char *ext;
265
- const char *p;
266
-
267
- StringValue(repl);
268
- p = RSTRING_PTR(str);
269
- extlen = RSTRING_LEN(str);
270
- ext = ruby_enc_find_extname(p, &extlen, rb_enc_get(str));
271
- if (ext == NULL) {
272
- ext = p + RSTRING_LEN(str);
273
- }
274
- else if (extlen <= 1) {
275
- ext += extlen;
276
- }
277
- str2 = rb_str_subseq(str, 0, ext-p);
278
- rb_str_append(str2, repl);
279
- return rb_class_new_instance(1, &str2, rb_obj_class(self));
280
- }
281
-
282
- /* Facade for File */
283
-
284
- /*
285
- * Returns the real (absolute) pathname for +self+ in the actual
286
- * filesystem.
287
- *
288
- * Does not contain symlinks or useless dots, +..+ and +.+.
289
- *
290
- * All components of the pathname must exist when this method is
291
- * called.
292
- *
293
- */
294
- static VALUE
295
- path_realpath(int argc, VALUE *argv, VALUE self)
296
- {
297
- VALUE basedir, str;
298
- rb_scan_args(argc, argv, "01", &basedir);
299
- str = rb_funcall(rb_cFile, id_realpath, 2, get_strpath(self), basedir);
300
- return rb_class_new_instance(1, &str, rb_obj_class(self));
301
- }
302
-
303
- /*
304
- * Returns the real (absolute) pathname of +self+ in the actual filesystem.
305
- *
306
- * Does not contain symlinks or useless dots, +..+ and +.+.
307
- *
308
- * The last component of the real pathname can be nonexistent.
309
- */
310
- static VALUE
311
- path_realdirpath(int argc, VALUE *argv, VALUE self)
312
- {
313
- VALUE basedir, str;
314
- rb_scan_args(argc, argv, "01", &basedir);
315
- str = rb_funcall(rb_cFile, id_realdirpath, 2, get_strpath(self), basedir);
316
- return rb_class_new_instance(1, &str, rb_obj_class(self));
317
- }
318
-
319
- /*
320
- * call-seq:
321
- * pathname.each_line {|line| ... }
322
- * pathname.each_line(sep=$/ [, open_args]) {|line| block } -> nil
323
- * pathname.each_line(limit [, open_args]) {|line| block } -> nil
324
- * pathname.each_line(sep, limit [, open_args]) {|line| block } -> nil
325
- * pathname.each_line(...) -> an_enumerator
326
- *
327
- * Iterates over each line in the file and yields a String object for each.
328
- */
329
- static VALUE
330
- path_each_line(int argc, VALUE *argv, VALUE self)
331
- {
332
- VALUE args[4];
333
- int n;
334
-
335
- args[0] = get_strpath(self);
336
- n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
337
- if (rb_block_given_p()) {
338
- return rb_block_call_kw(rb_cFile, id_foreach, 1+n, args, 0, 0, RB_PASS_CALLED_KEYWORDS);
339
- }
340
- else {
341
- return rb_funcallv_kw(rb_cFile, id_foreach, 1+n, args, RB_PASS_CALLED_KEYWORDS);
342
- }
343
- }
344
-
345
- /*
346
- * call-seq:
347
- * pathname.read([length [, offset]]) -> string
348
- * pathname.read([length [, offset]], open_args) -> string
349
- *
350
- * Returns all data from the file, or the first +N+ bytes if specified.
351
- *
352
- * See File.read.
353
- *
354
- */
355
- static VALUE
356
- path_read(int argc, VALUE *argv, VALUE self)
357
- {
358
- VALUE args[4];
359
- int n;
360
-
361
- args[0] = get_strpath(self);
362
- n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
363
- return rb_funcallv_kw(rb_cFile, id_read, 1+n, args, RB_PASS_CALLED_KEYWORDS);
364
- }
365
-
366
- /*
367
- * call-seq:
368
- * pathname.binread([length [, offset]]) -> string
369
- *
370
- * Returns all the bytes from the file, or the first +N+ if specified.
371
- *
372
- * See File.binread.
373
- *
374
- */
375
- static VALUE
376
- path_binread(int argc, VALUE *argv, VALUE self)
377
- {
378
- VALUE args[3];
379
- int n;
380
-
381
- args[0] = get_strpath(self);
382
- n = rb_scan_args(argc, argv, "02", &args[1], &args[2]);
383
- return rb_funcallv(rb_cFile, id_binread, 1+n, args);
384
- }
385
-
386
- /*
387
- * call-seq:
388
- * pathname.write(string, [offset] ) => fixnum
389
- * pathname.write(string, [offset], open_args ) => fixnum
390
- *
391
- * Writes +contents+ to the file.
392
- *
393
- * See File.write.
394
- *
395
- */
396
- static VALUE
397
- path_write(int argc, VALUE *argv, VALUE self)
398
- {
399
- VALUE args[4];
400
- int n;
401
-
402
- args[0] = get_strpath(self);
403
- n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
404
- return rb_funcallv_kw(rb_cFile, id_write, 1+n, args, RB_PASS_CALLED_KEYWORDS);
405
- }
406
-
407
- /*
408
- * call-seq:
409
- * pathname.binwrite(string, [offset] ) => fixnum
410
- * pathname.binwrite(string, [offset], open_args ) => fixnum
411
- *
412
- * Writes +contents+ to the file, opening it in binary mode.
413
- *
414
- * See File.binwrite.
415
- *
416
- */
417
- static VALUE
418
- path_binwrite(int argc, VALUE *argv, VALUE self)
419
- {
420
- VALUE args[4];
421
- int n;
422
-
423
- args[0] = get_strpath(self);
424
- n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
425
- return rb_funcallv_kw(rb_cFile, id_binwrite, 1+n, args, RB_PASS_CALLED_KEYWORDS);
426
- }
427
-
428
- /*
429
- * call-seq:
430
- * pathname.readlines(sep=$/ [, open_args]) -> array
431
- * pathname.readlines(limit [, open_args]) -> array
432
- * pathname.readlines(sep, limit [, open_args]) -> array
433
- *
434
- * Returns all the lines from the file.
435
- *
436
- * See File.readlines.
437
- *
438
- */
439
- static VALUE
440
- path_readlines(int argc, VALUE *argv, VALUE self)
441
- {
442
- VALUE args[4];
443
- int n;
444
-
445
- args[0] = get_strpath(self);
446
- n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
447
- return rb_funcallv_kw(rb_cFile, id_readlines, 1+n, args, RB_PASS_CALLED_KEYWORDS);
448
- }
449
-
450
- /*
451
- * call-seq:
452
- * pathname.sysopen([mode, [perm]]) -> fixnum
453
- *
454
- * See IO.sysopen.
455
- *
456
- */
457
- static VALUE
458
- path_sysopen(int argc, VALUE *argv, VALUE self)
459
- {
460
- VALUE args[3];
461
- int n;
462
-
463
- args[0] = get_strpath(self);
464
- n = rb_scan_args(argc, argv, "02", &args[1], &args[2]);
465
- return rb_funcallv(rb_cIO, id_sysopen, 1+n, args);
466
- }
467
-
468
- /*
469
- * call-seq:
470
- * pathname.atime -> time
471
- *
472
- * Returns the last access time for the file.
473
- *
474
- * See File.atime.
475
- */
476
- static VALUE
477
- path_atime(VALUE self)
478
- {
479
- return rb_funcall(rb_cFile, id_atime, 1, get_strpath(self));
480
- }
481
-
482
- /*
483
- * call-seq:
484
- * pathname.birthtime -> time
485
- *
486
- * Returns the birth time for the file.
487
- * If the platform doesn't have birthtime, raises NotImplementedError.
488
- *
489
- * See File.birthtime.
490
- */
491
- static VALUE
492
- path_birthtime(VALUE self)
493
- {
494
- return rb_funcall(rb_cFile, id_birthtime, 1, get_strpath(self));
495
- }
496
-
497
- /*
498
- * call-seq:
499
- * pathname.ctime -> time
500
- *
501
- * Returns the last change time, using directory information, not the file itself.
502
- *
503
- * See File.ctime.
504
- */
505
- static VALUE
506
- path_ctime(VALUE self)
507
- {
508
- return rb_funcall(rb_cFile, id_ctime, 1, get_strpath(self));
509
- }
510
-
511
- /*
512
- * call-seq:
513
- * pathname.mtime -> time
514
- *
515
- * Returns the last modified time of the file.
516
- *
517
- * See File.mtime.
518
- */
519
- static VALUE
520
- path_mtime(VALUE self)
521
- {
522
- return rb_funcall(rb_cFile, id_mtime, 1, get_strpath(self));
523
- }
524
-
525
- /*
526
- * call-seq:
527
- * pathname.chmod(mode_int) -> integer
528
- *
529
- * Changes file permissions.
530
- *
531
- * See File.chmod.
532
- */
533
- static VALUE
534
- path_chmod(VALUE self, VALUE mode)
535
- {
536
- return rb_funcall(rb_cFile, id_chmod, 2, mode, get_strpath(self));
537
- }
538
-
539
- /*
540
- * call-seq:
541
- * pathname.lchmod(mode_int) -> integer
542
- *
543
- * Same as Pathname.chmod, but does not follow symbolic links.
544
- *
545
- * See File.lchmod.
546
- */
547
- static VALUE
548
- path_lchmod(VALUE self, VALUE mode)
549
- {
550
- return rb_funcall(rb_cFile, id_lchmod, 2, mode, get_strpath(self));
551
- }
552
-
553
- /*
554
- * call-seq:
555
- * pathname.chown(owner_int, group_int) -> integer
556
- *
557
- * Change owner and group of the file.
558
- *
559
- * See File.chown.
560
- */
561
- static VALUE
562
- path_chown(VALUE self, VALUE owner, VALUE group)
563
- {
564
- return rb_funcall(rb_cFile, id_chown, 3, owner, group, get_strpath(self));
565
- }
566
-
567
- /*
568
- * call-seq:
569
- * pathname.lchown(owner_int, group_int) -> integer
570
- *
571
- * Same as Pathname.chown, but does not follow symbolic links.
572
- *
573
- * See File.lchown.
574
- */
575
- static VALUE
576
- path_lchown(VALUE self, VALUE owner, VALUE group)
577
- {
578
- return rb_funcall(rb_cFile, id_lchown, 3, owner, group, get_strpath(self));
579
- }
580
-
581
- /*
582
- * call-seq:
583
- * pathname.fnmatch(pattern, [flags]) -> true or false
584
- * pathname.fnmatch?(pattern, [flags]) -> true or false
585
- *
586
- * Return +true+ if the receiver matches the given pattern.
587
- *
588
- * See File.fnmatch.
589
- */
590
- static VALUE
591
- path_fnmatch(int argc, VALUE *argv, VALUE self)
592
- {
593
- VALUE str = get_strpath(self);
594
- VALUE pattern, flags;
595
- if (rb_scan_args(argc, argv, "11", &pattern, &flags) == 1)
596
- return rb_funcall(rb_cFile, id_fnmatch, 2, pattern, str);
597
- else
598
- return rb_funcall(rb_cFile, id_fnmatch, 3, pattern, str, flags);
599
- }
86
+ static void init_ids(void);
600
87
 
601
- /*
602
- * call-seq:
603
- * pathname.ftype -> string
604
- *
605
- * Returns "type" of file ("file", "directory", etc).
606
- *
607
- * See File.ftype.
608
- */
609
- static VALUE
610
- path_ftype(VALUE self)
88
+ void
89
+ Init_pathname(void)
611
90
  {
612
- return rb_funcall(rb_cFile, id_ftype, 1, get_strpath(self));
613
- }
91
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
92
+ rb_ext_ractor_safe(true);
93
+ #endif
614
94
 
615
- /*
616
- * call-seq:
617
- * pathname.make_link(old)
618
- *
619
- * Creates a hard link at _pathname_.
620
- *
621
- * See File.link.
622
- */
623
- static VALUE
624
- path_make_link(VALUE self, VALUE old)
625
- {
626
- return rb_funcall(rb_cFile, id_link, 2, old, get_strpath(self));
95
+ init_ids();
96
+ InitVM(pathname);
627
97
  }
628
98
 
629
- /*
630
- * call-seq:
631
- * pathname.open()
632
- * pathname.open(mode="r" [, opt]) -> file
633
- * pathname.open([mode [, perm]] [, opt]) -> file
634
- * pathname.open(mode="r" [, opt]) {|file| block } -> obj
635
- * pathname.open([mode [, perm]] [, opt]) {|file| block } -> obj
636
- *
637
- * Opens the file for reading or writing.
638
- *
639
- * See File.open.
640
- */
641
- static VALUE
642
- path_open(int argc, VALUE *argv, VALUE self)
99
+ void
100
+ InitVM_pathname(void)
643
101
  {
644
- VALUE args[4];
645
- int n;
646
-
647
- args[0] = get_strpath(self);
648
- n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
649
- if (rb_block_given_p()) {
650
- return rb_block_call_kw(rb_cFile, id_open, 1+n, args, 0, 0, RB_PASS_CALLED_KEYWORDS);
651
- }
652
- else {
653
- return rb_funcallv_kw(rb_cFile, id_open, 1+n, args, RB_PASS_CALLED_KEYWORDS);
654
- }
655
- }
656
-
657
- /*
658
- * Read symbolic link.
659
- *
660
- * See File.readlink.
661
- */
662
- static VALUE
663
- path_readlink(VALUE self)
664
- {
665
- VALUE str;
666
- str = rb_funcall(rb_cFile, id_readlink, 1, get_strpath(self));
667
- return rb_class_new_instance(1, &str, rb_obj_class(self));
668
- }
669
-
670
- /*
671
- * Rename the file.
672
- *
673
- * See File.rename.
674
- */
675
- static VALUE
676
- path_rename(VALUE self, VALUE to)
677
- {
678
- return rb_funcall(rb_cFile, id_rename, 2, get_strpath(self), to);
679
- }
680
-
681
- /*
682
- * Returns a File::Stat object.
683
- *
684
- * See File.stat.
685
- */
686
- static VALUE
687
- path_stat(VALUE self)
688
- {
689
- return rb_funcall(rb_cFile, id_stat, 1, get_strpath(self));
690
- }
691
-
692
- /*
693
- * See File.lstat.
694
- */
695
- static VALUE
696
- path_lstat(VALUE self)
697
- {
698
- return rb_funcall(rb_cFile, id_lstat, 1, get_strpath(self));
699
- }
700
-
701
- /*
702
- * call-seq:
703
- * pathname.make_symlink(old)
704
- *
705
- * Creates a symbolic link.
706
- *
707
- * See File.symlink.
708
- */
709
- static VALUE
710
- path_make_symlink(VALUE self, VALUE old)
711
- {
712
- return rb_funcall(rb_cFile, id_symlink, 2, old, get_strpath(self));
713
- }
714
-
715
- /*
716
- * Truncates the file to +length+ bytes.
717
- *
718
- * See File.truncate.
719
- */
720
- static VALUE
721
- path_truncate(VALUE self, VALUE length)
722
- {
723
- return rb_funcall(rb_cFile, id_truncate, 2, get_strpath(self), length);
724
- }
725
-
726
- /*
727
- * Update the access and modification times of the file.
728
- *
729
- * See File.utime.
730
- */
731
- static VALUE
732
- path_utime(VALUE self, VALUE atime, VALUE mtime)
733
- {
734
- return rb_funcall(rb_cFile, id_utime, 3, atime, mtime, get_strpath(self));
735
- }
736
-
737
- /*
738
- * Update the access and modification times of the file.
739
- *
740
- * Same as Pathname#utime, but does not follow symbolic links.
741
- *
742
- * See File.lutime.
743
- */
744
- static VALUE
745
- path_lutime(VALUE self, VALUE atime, VALUE mtime)
746
- {
747
- return rb_funcall(rb_cFile, id_lutime, 3, atime, mtime, get_strpath(self));
748
- }
749
-
750
- /*
751
- * Returns the last component of the path.
752
- *
753
- * See File.basename.
754
- */
755
- static VALUE
756
- path_basename(int argc, VALUE *argv, VALUE self)
757
- {
758
- VALUE str = get_strpath(self);
759
- VALUE fext;
760
- if (rb_scan_args(argc, argv, "01", &fext) == 0)
761
- str = rb_funcall(rb_cFile, id_basename, 1, str);
762
- else
763
- str = rb_funcall(rb_cFile, id_basename, 2, str, fext);
764
- return rb_class_new_instance(1, &str, rb_obj_class(self));
765
- }
766
-
767
- /*
768
- * Returns all but the last component of the path.
769
- *
770
- * See File.dirname.
771
- */
772
- static VALUE
773
- path_dirname(VALUE self)
774
- {
775
- VALUE str = get_strpath(self);
776
- str = rb_funcall(rb_cFile, id_dirname, 1, str);
777
- return rb_class_new_instance(1, &str, rb_obj_class(self));
778
- }
779
-
780
- /*
781
- * Returns the file's extension.
782
- *
783
- * See File.extname.
784
- */
785
- static VALUE
786
- path_extname(VALUE self)
787
- {
788
- VALUE str = get_strpath(self);
789
- return rb_funcall(rb_cFile, id_extname, 1, str);
790
- }
791
-
792
- /*
793
- * Returns the absolute path for the file.
794
- *
795
- * See File.expand_path.
796
- */
797
- static VALUE
798
- path_expand_path(int argc, VALUE *argv, VALUE self)
799
- {
800
- VALUE str = get_strpath(self);
801
- VALUE dname;
802
- if (rb_scan_args(argc, argv, "01", &dname) == 0)
803
- str = rb_funcall(rb_cFile, id_expand_path, 1, str);
804
- else
805
- str = rb_funcall(rb_cFile, id_expand_path, 2, str, dname);
806
- return rb_class_new_instance(1, &str, rb_obj_class(self));
807
- }
808
-
809
- /*
810
- * Returns the #dirname and the #basename in an Array.
811
- *
812
- * See File.split.
813
- */
814
- static VALUE
815
- path_split(VALUE self)
816
- {
817
- VALUE str = get_strpath(self);
818
- VALUE ary, dirname, basename;
819
- ary = rb_funcall(rb_cFile, id_split, 1, str);
820
- Check_Type(ary, T_ARRAY);
821
- dirname = rb_ary_entry(ary, 0);
822
- basename = rb_ary_entry(ary, 1);
823
- dirname = rb_class_new_instance(1, &dirname, rb_obj_class(self));
824
- basename = rb_class_new_instance(1, &basename, rb_obj_class(self));
825
- return rb_ary_new3(2, dirname, basename);
826
- }
827
-
828
- /*
829
- * See FileTest.blockdev?.
830
- */
831
- static VALUE
832
- path_blockdev_p(VALUE self)
833
- {
834
- return rb_funcall(rb_mFileTest, id_blockdev_p, 1, get_strpath(self));
835
- }
836
-
837
- /*
838
- * See FileTest.chardev?.
839
- */
840
- static VALUE
841
- path_chardev_p(VALUE self)
842
- {
843
- return rb_funcall(rb_mFileTest, id_chardev_p, 1, get_strpath(self));
844
- }
845
-
846
- /*
847
- * See FileTest.executable?.
848
- */
849
- static VALUE
850
- path_executable_p(VALUE self)
851
- {
852
- return rb_funcall(rb_mFileTest, id_executable_p, 1, get_strpath(self));
853
- }
854
-
855
- /*
856
- * See FileTest.executable_real?.
857
- */
858
- static VALUE
859
- path_executable_real_p(VALUE self)
860
- {
861
- return rb_funcall(rb_mFileTest, id_executable_real_p, 1, get_strpath(self));
862
- }
863
-
864
- /*
865
- * See FileTest.exist?.
866
- */
867
- static VALUE
868
- path_exist_p(VALUE self)
869
- {
870
- return rb_funcall(rb_mFileTest, id_exist_p, 1, get_strpath(self));
871
- }
872
-
873
- /*
874
- * See FileTest.grpowned?.
875
- */
876
- static VALUE
877
- path_grpowned_p(VALUE self)
878
- {
879
- return rb_funcall(rb_mFileTest, id_grpowned_p, 1, get_strpath(self));
880
- }
881
-
882
- /*
883
- * See FileTest.directory?.
884
- */
885
- static VALUE
886
- path_directory_p(VALUE self)
887
- {
888
- return rb_funcall(rb_mFileTest, id_directory_p, 1, get_strpath(self));
889
- }
890
-
891
- /*
892
- * See FileTest.file?.
893
- */
894
- static VALUE
895
- path_file_p(VALUE self)
896
- {
897
- return rb_funcall(rb_mFileTest, id_file_p, 1, get_strpath(self));
898
- }
899
-
900
- /*
901
- * See FileTest.pipe?.
902
- */
903
- static VALUE
904
- path_pipe_p(VALUE self)
905
- {
906
- return rb_funcall(rb_mFileTest, id_pipe_p, 1, get_strpath(self));
907
- }
908
-
909
- /*
910
- * See FileTest.socket?.
911
- */
912
- static VALUE
913
- path_socket_p(VALUE self)
914
- {
915
- return rb_funcall(rb_mFileTest, id_socket_p, 1, get_strpath(self));
916
- }
917
-
918
- /*
919
- * See FileTest.owned?.
920
- */
921
- static VALUE
922
- path_owned_p(VALUE self)
923
- {
924
- return rb_funcall(rb_mFileTest, id_owned_p, 1, get_strpath(self));
925
- }
926
-
927
- /*
928
- * See FileTest.readable?.
929
- */
930
- static VALUE
931
- path_readable_p(VALUE self)
932
- {
933
- return rb_funcall(rb_mFileTest, id_readable_p, 1, get_strpath(self));
934
- }
935
-
936
- /*
937
- * See FileTest.world_readable?.
938
- */
939
- static VALUE
940
- path_world_readable_p(VALUE self)
941
- {
942
- return rb_funcall(rb_mFileTest, id_world_readable_p, 1, get_strpath(self));
943
- }
944
-
945
- /*
946
- * See FileTest.readable_real?.
947
- */
948
- static VALUE
949
- path_readable_real_p(VALUE self)
950
- {
951
- return rb_funcall(rb_mFileTest, id_readable_real_p, 1, get_strpath(self));
952
- }
953
-
954
- /*
955
- * See FileTest.setuid?.
956
- */
957
- static VALUE
958
- path_setuid_p(VALUE self)
959
- {
960
- return rb_funcall(rb_mFileTest, id_setuid_p, 1, get_strpath(self));
961
- }
962
-
963
- /*
964
- * See FileTest.setgid?.
965
- */
966
- static VALUE
967
- path_setgid_p(VALUE self)
968
- {
969
- return rb_funcall(rb_mFileTest, id_setgid_p, 1, get_strpath(self));
970
- }
971
-
972
- /*
973
- * See FileTest.size.
974
- */
975
- static VALUE
976
- path_size(VALUE self)
977
- {
978
- return rb_funcall(rb_mFileTest, id_size, 1, get_strpath(self));
979
- }
980
-
981
- /*
982
- * See FileTest.size?.
983
- */
984
- static VALUE
985
- path_size_p(VALUE self)
986
- {
987
- return rb_funcall(rb_mFileTest, id_size_p, 1, get_strpath(self));
988
- }
989
-
990
- /*
991
- * See FileTest.sticky?.
992
- */
993
- static VALUE
994
- path_sticky_p(VALUE self)
995
- {
996
- return rb_funcall(rb_mFileTest, id_sticky_p, 1, get_strpath(self));
997
- }
998
-
999
- /*
1000
- * See FileTest.symlink?.
1001
- */
1002
- static VALUE
1003
- path_symlink_p(VALUE self)
1004
- {
1005
- return rb_funcall(rb_mFileTest, id_symlink_p, 1, get_strpath(self));
1006
- }
1007
-
1008
- /*
1009
- * See FileTest.writable?.
1010
- */
1011
- static VALUE
1012
- path_writable_p(VALUE self)
1013
- {
1014
- return rb_funcall(rb_mFileTest, id_writable_p, 1, get_strpath(self));
1015
- }
1016
-
1017
- /*
1018
- * See FileTest.world_writable?.
1019
- */
1020
- static VALUE
1021
- path_world_writable_p(VALUE self)
1022
- {
1023
- return rb_funcall(rb_mFileTest, id_world_writable_p, 1, get_strpath(self));
1024
- }
1025
-
1026
- /*
1027
- * See FileTest.writable_real?.
1028
- */
1029
- static VALUE
1030
- path_writable_real_p(VALUE self)
1031
- {
1032
- return rb_funcall(rb_mFileTest, id_writable_real_p, 1, get_strpath(self));
1033
- }
1034
-
1035
- /*
1036
- * See FileTest.zero?.
1037
- */
1038
- static VALUE
1039
- path_zero_p(VALUE self)
1040
- {
1041
- return rb_funcall(rb_mFileTest, id_zero_p, 1, get_strpath(self));
1042
- }
1043
-
1044
- /*
1045
- * Tests the file is empty.
1046
- *
1047
- * See Dir#empty? and FileTest.empty?.
1048
- */
1049
- static VALUE
1050
- path_empty_p(VALUE self)
1051
- {
1052
-
1053
- VALUE path = get_strpath(self);
1054
- if (RTEST(rb_funcall(rb_mFileTest, id_directory_p, 1, path)))
1055
- return rb_funcall(rb_cDir, id_empty_p, 1, path);
1056
- else
1057
- return rb_funcall(rb_mFileTest, id_empty_p, 1, path);
1058
- }
1059
-
1060
- static VALUE
1061
- s_glob_i(RB_BLOCK_CALL_FUNC_ARGLIST(elt, klass))
1062
- {
1063
- return rb_yield(rb_class_new_instance(1, &elt, klass));
1064
- }
1065
-
1066
- /*
1067
- * Returns or yields Pathname objects.
1068
- *
1069
- * Pathname.glob("lib/i*.rb")
1070
- * #=> [#<Pathname:lib/ipaddr.rb>, #<Pathname:lib/irb.rb>]
1071
- *
1072
- * See Dir.glob.
1073
- */
1074
- static VALUE
1075
- path_s_glob(int argc, VALUE *argv, VALUE klass)
1076
- {
1077
- VALUE args[3];
1078
- int n;
1079
-
1080
- n = rb_scan_args(argc, argv, "12", &args[0], &args[1], &args[2]);
1081
- if (rb_block_given_p()) {
1082
- return rb_block_call_kw(rb_cDir, id_glob, n, args, s_glob_i, klass, RB_PASS_CALLED_KEYWORDS);
1083
- }
1084
- else {
1085
- VALUE ary;
1086
- long i;
1087
- ary = rb_funcallv_kw(rb_cDir, id_glob, n, args, RB_PASS_CALLED_KEYWORDS);
1088
- ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
1089
- for (i = 0; i < RARRAY_LEN(ary); i++) {
1090
- VALUE elt = RARRAY_AREF(ary, i);
1091
- elt = rb_class_new_instance(1, &elt, klass);
1092
- rb_ary_store(ary, i, elt);
1093
- }
1094
- return ary;
1095
- }
1096
- }
1097
-
1098
- static VALUE
1099
- glob_i(RB_BLOCK_CALL_FUNC_ARGLIST(elt, self))
1100
- {
1101
- elt = rb_funcall(self, '+', 1, elt);
1102
- return rb_yield(elt);
1103
- }
1104
-
1105
- /*
1106
- * Returns or yields Pathname objects.
1107
- *
1108
- * Pathname("ruby-2.4.2").glob("R*.md")
1109
- * #=> [#<Pathname:ruby-2.4.2/README.md>, #<Pathname:ruby-2.4.2/README.ja.md>]
1110
- *
1111
- * See Dir.glob.
1112
- * This method uses the +base+ keyword argument of Dir.glob.
1113
- */
1114
- static VALUE
1115
- path_glob(int argc, VALUE *argv, VALUE self)
1116
- {
1117
- VALUE args[3];
1118
- int n;
1119
-
1120
- n = rb_scan_args(argc, argv, "11", &args[0], &args[1]);
1121
- if (n == 1)
1122
- args[1] = INT2FIX(0);
1123
-
1124
- args[2] = rb_hash_new();
1125
- rb_hash_aset(args[2], ID2SYM(id_base), get_strpath(self));
1126
-
1127
- n = 3;
1128
-
1129
- if (rb_block_given_p()) {
1130
- return rb_block_call_kw(rb_cDir, id_glob, n, args, glob_i, self, RB_PASS_KEYWORDS);
1131
- }
1132
- else {
1133
- VALUE ary;
1134
- long i;
1135
- ary = rb_funcallv_kw(rb_cDir, id_glob, n, args, RB_PASS_KEYWORDS);
1136
- ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
1137
- for (i = 0; i < RARRAY_LEN(ary); i++) {
1138
- VALUE elt = RARRAY_AREF(ary, i);
1139
- elt = rb_funcall(self, '+', 1, elt);
1140
- rb_ary_store(ary, i, elt);
1141
- }
1142
- return ary;
1143
- }
1144
- }
1145
-
1146
- /*
1147
- * Returns the current working directory as a Pathname.
1148
- *
1149
- * Pathname.getwd
1150
- * #=> #<Pathname:/home/zzak/projects/ruby>
1151
- *
1152
- * See Dir.getwd.
1153
- */
1154
- static VALUE
1155
- path_s_getwd(VALUE klass)
1156
- {
1157
- VALUE str;
1158
- str = rb_funcall(rb_cDir, id_getwd, 0);
1159
- return rb_class_new_instance(1, &str, klass);
1160
- }
1161
-
1162
- /*
1163
- * Return the entries (files and subdirectories) in the directory, each as a
1164
- * Pathname object.
1165
- *
1166
- * The results contains just the names in the directory, without any trailing
1167
- * slashes or recursive look-up.
1168
- *
1169
- * pp Pathname.new('/usr/local').entries
1170
- * #=> [#<Pathname:share>,
1171
- * # #<Pathname:lib>,
1172
- * # #<Pathname:..>,
1173
- * # #<Pathname:include>,
1174
- * # #<Pathname:etc>,
1175
- * # #<Pathname:bin>,
1176
- * # #<Pathname:man>,
1177
- * # #<Pathname:games>,
1178
- * # #<Pathname:.>,
1179
- * # #<Pathname:sbin>,
1180
- * # #<Pathname:src>]
1181
- *
1182
- * The result may contain the current directory <code>#<Pathname:.></code> and
1183
- * the parent directory <code>#<Pathname:..></code>.
1184
- *
1185
- * If you don't want +.+ and +..+ and
1186
- * want directories, consider Pathname#children.
1187
- */
1188
- static VALUE
1189
- path_entries(VALUE self)
1190
- {
1191
- VALUE klass, str, ary;
1192
- long i;
1193
- klass = rb_obj_class(self);
1194
- str = get_strpath(self);
1195
- ary = rb_funcall(rb_cDir, id_entries, 1, str);
1196
- ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
1197
- for (i = 0; i < RARRAY_LEN(ary); i++) {
1198
- VALUE elt = RARRAY_AREF(ary, i);
1199
- elt = rb_class_new_instance(1, &elt, klass);
1200
- rb_ary_store(ary, i, elt);
1201
- }
1202
- return ary;
1203
- }
1204
-
1205
- /*
1206
- * Create the referenced directory.
1207
- *
1208
- * See Dir.mkdir.
1209
- */
1210
- static VALUE
1211
- path_mkdir(int argc, VALUE *argv, VALUE self)
1212
- {
1213
- VALUE str = get_strpath(self);
1214
- VALUE vmode;
1215
- if (rb_scan_args(argc, argv, "01", &vmode) == 0)
1216
- return rb_funcall(rb_cDir, id_mkdir, 1, str);
1217
- else
1218
- return rb_funcall(rb_cDir, id_mkdir, 2, str, vmode);
1219
- }
1220
-
1221
- /*
1222
- * Remove the referenced directory.
1223
- *
1224
- * See Dir.rmdir.
1225
- */
1226
- static VALUE
1227
- path_rmdir(VALUE self)
1228
- {
1229
- return rb_funcall(rb_cDir, id_rmdir, 1, get_strpath(self));
1230
- }
1231
-
1232
- /*
1233
- * Opens the referenced directory.
1234
- *
1235
- * See Dir.open.
1236
- */
1237
- static VALUE
1238
- path_opendir(VALUE self)
1239
- {
1240
- VALUE args[1];
1241
-
1242
- args[0] = get_strpath(self);
1243
- return rb_block_call(rb_cDir, id_open, 1, args, 0, 0);
1244
- }
1245
-
1246
- static VALUE
1247
- each_entry_i(RB_BLOCK_CALL_FUNC_ARGLIST(elt, klass))
1248
- {
1249
- return rb_yield(rb_class_new_instance(1, &elt, klass));
1250
- }
1251
-
1252
- /*
1253
- * Iterates over the entries (files and subdirectories) in the directory,
1254
- * yielding a Pathname object for each entry.
1255
- */
1256
- static VALUE
1257
- path_each_entry(VALUE self)
1258
- {
1259
- VALUE args[1];
1260
- RETURN_ENUMERATOR(self, 0, 0);
1261
-
1262
- args[0] = get_strpath(self);
1263
- return rb_block_call(rb_cDir, id_foreach, 1, args, each_entry_i, rb_obj_class(self));
1264
- }
1265
-
1266
- static VALUE
1267
- unlink_body(VALUE str)
1268
- {
1269
- return rb_funcall(rb_cDir, id_unlink, 1, str);
1270
- }
1271
-
1272
- static VALUE
1273
- unlink_rescue(VALUE str, VALUE errinfo)
1274
- {
1275
- return rb_funcall(rb_cFile, id_unlink, 1, str);
1276
- }
1277
-
1278
- /*
1279
- * Removes a file or directory, using File.unlink if +self+ is a file, or
1280
- * Dir.unlink as necessary.
1281
- */
1282
- static VALUE
1283
- path_unlink(VALUE self)
1284
- {
1285
- VALUE eENOTDIR = rb_const_get_at(rb_mErrno, id_ENOTDIR);
1286
- VALUE str = get_strpath(self);
1287
- return rb_rescue2(unlink_body, str, unlink_rescue, str, eENOTDIR, (VALUE)0);
1288
- }
1289
-
1290
- /*
1291
- * :call-seq:
1292
- * Pathname(path) -> pathname
1293
- *
1294
- * Creates a new Pathname object from the given string, +path+, and returns
1295
- * pathname object.
1296
- *
1297
- * In order to use this constructor, you must first require the Pathname
1298
- * standard library extension.
1299
- *
1300
- * require 'pathname'
1301
- * Pathname("/home/zzak")
1302
- * #=> #<Pathname:/home/zzak>
1303
- *
1304
- * See also Pathname::new for more information.
1305
- */
1306
- static VALUE
1307
- path_f_pathname(VALUE self, VALUE str)
1308
- {
1309
- if (CLASS_OF(str) == rb_cPathname)
1310
- return str;
1311
- return rb_class_new_instance(1, &str, rb_cPathname);
1312
- }
1313
-
1314
- /*
1315
- *
1316
- * Pathname represents the name of a file or directory on the filesystem,
1317
- * but not the file itself.
1318
- *
1319
- * The pathname depends on the Operating System: Unix, Windows, etc.
1320
- * This library works with pathnames of local OS, however non-Unix pathnames
1321
- * are supported experimentally.
1322
- *
1323
- * A Pathname can be relative or absolute. It's not until you try to
1324
- * reference the file that it even matters whether the file exists or not.
1325
- *
1326
- * Pathname is immutable. It has no method for destructive update.
1327
- *
1328
- * The goal of this class is to manipulate file path information in a neater
1329
- * way than standard Ruby provides. The examples below demonstrate the
1330
- * difference.
1331
- *
1332
- * *All* functionality from File, FileTest, and some from Dir and FileUtils is
1333
- * included, in an unsurprising way. It is essentially a facade for all of
1334
- * these, and more.
1335
- *
1336
- * == Examples
1337
- *
1338
- * === Example 1: Using Pathname
1339
- *
1340
- * require 'pathname'
1341
- * pn = Pathname.new("/usr/bin/ruby")
1342
- * size = pn.size # 27662
1343
- * isdir = pn.directory? # false
1344
- * dir = pn.dirname # Pathname:/usr/bin
1345
- * base = pn.basename # Pathname:ruby
1346
- * dir, base = pn.split # [Pathname:/usr/bin, Pathname:ruby]
1347
- * data = pn.read
1348
- * pn.open { |f| _ }
1349
- * pn.each_line { |line| _ }
1350
- *
1351
- * === Example 2: Using standard Ruby
1352
- *
1353
- * pn = "/usr/bin/ruby"
1354
- * size = File.size(pn) # 27662
1355
- * isdir = File.directory?(pn) # false
1356
- * dir = File.dirname(pn) # "/usr/bin"
1357
- * base = File.basename(pn) # "ruby"
1358
- * dir, base = File.split(pn) # ["/usr/bin", "ruby"]
1359
- * data = File.read(pn)
1360
- * File.open(pn) { |f| _ }
1361
- * File.foreach(pn) { |line| _ }
1362
- *
1363
- * === Example 3: Special features
1364
- *
1365
- * p1 = Pathname.new("/usr/lib") # Pathname:/usr/lib
1366
- * p2 = p1 + "ruby/1.8" # Pathname:/usr/lib/ruby/1.8
1367
- * p3 = p1.parent # Pathname:/usr
1368
- * p4 = p2.relative_path_from(p3) # Pathname:lib/ruby/1.8
1369
- * pwd = Pathname.pwd # Pathname:/home/gavin
1370
- * pwd.absolute? # true
1371
- * p5 = Pathname.new "." # Pathname:.
1372
- * p5 = p5 + "music/../articles" # Pathname:music/../articles
1373
- * p5.cleanpath # Pathname:articles
1374
- * p5.realpath # Pathname:/home/gavin/articles
1375
- * p5.children # [Pathname:/home/gavin/articles/linux, ...]
1376
- *
1377
- * == Breakdown of functionality
1378
- *
1379
- * === Core methods
1380
- *
1381
- * These methods are effectively manipulating a String, because that's
1382
- * all a path is. None of these access the file system except for
1383
- * #mountpoint?, #children, #each_child, #realdirpath and #realpath.
1384
- *
1385
- * - +
1386
- * - #join
1387
- * - #parent
1388
- * - #root?
1389
- * - #absolute?
1390
- * - #relative?
1391
- * - #relative_path_from
1392
- * - #each_filename
1393
- * - #cleanpath
1394
- * - #realpath
1395
- * - #realdirpath
1396
- * - #children
1397
- * - #each_child
1398
- * - #mountpoint?
1399
- *
1400
- * === File status predicate methods
1401
- *
1402
- * These methods are a facade for FileTest:
1403
- * - #blockdev?
1404
- * - #chardev?
1405
- * - #directory?
1406
- * - #executable?
1407
- * - #executable_real?
1408
- * - #exist?
1409
- * - #file?
1410
- * - #grpowned?
1411
- * - #owned?
1412
- * - #pipe?
1413
- * - #readable?
1414
- * - #world_readable?
1415
- * - #readable_real?
1416
- * - #setgid?
1417
- * - #setuid?
1418
- * - #size
1419
- * - #size?
1420
- * - #socket?
1421
- * - #sticky?
1422
- * - #symlink?
1423
- * - #writable?
1424
- * - #world_writable?
1425
- * - #writable_real?
1426
- * - #zero?
1427
- *
1428
- * === File property and manipulation methods
1429
- *
1430
- * These methods are a facade for File:
1431
- * - #atime
1432
- * - #birthtime
1433
- * - #ctime
1434
- * - #mtime
1435
- * - #chmod(mode)
1436
- * - #lchmod(mode)
1437
- * - #chown(owner, group)
1438
- * - #lchown(owner, group)
1439
- * - #fnmatch(pattern, *args)
1440
- * - #fnmatch?(pattern, *args)
1441
- * - #ftype
1442
- * - #make_link(old)
1443
- * - #open(*args, &block)
1444
- * - #readlink
1445
- * - #rename(to)
1446
- * - #stat
1447
- * - #lstat
1448
- * - #make_symlink(old)
1449
- * - #truncate(length)
1450
- * - #utime(atime, mtime)
1451
- * - #lutime(atime, mtime)
1452
- * - #basename(*args)
1453
- * - #dirname
1454
- * - #extname
1455
- * - #expand_path(*args)
1456
- * - #split
1457
- *
1458
- * === Directory methods
1459
- *
1460
- * These methods are a facade for Dir:
1461
- * - Pathname.glob(*args)
1462
- * - Pathname.getwd / Pathname.pwd
1463
- * - #rmdir
1464
- * - #entries
1465
- * - #each_entry(&block)
1466
- * - #mkdir(*args)
1467
- * - #opendir(*args)
1468
- *
1469
- * === IO
1470
- *
1471
- * These methods are a facade for IO:
1472
- * - #each_line(*args, &block)
1473
- * - #read(*args)
1474
- * - #binread(*args)
1475
- * - #readlines(*args)
1476
- * - #sysopen(*args)
1477
- * - #write(*args)
1478
- * - #binwrite(*args)
1479
- *
1480
- * === Utilities
1481
- *
1482
- * These methods are a mixture of Find, FileUtils, and others:
1483
- * - #find(&block)
1484
- * - #mkpath
1485
- * - #rmtree
1486
- * - #unlink / #delete
1487
- *
1488
- *
1489
- * == Method documentation
1490
- *
1491
- * As the above section shows, most of the methods in Pathname are facades. The
1492
- * documentation for these methods generally just says, for instance, "See
1493
- * FileTest.writable?", as you should be familiar with the original method
1494
- * anyway, and its documentation (e.g. through +ri+) will contain more
1495
- * information. In some cases, a brief description will follow.
1496
- */
1497
- void
1498
- Init_pathname(void)
1499
- {
1500
- #ifdef HAVE_RB_EXT_RACTOR_SAFE
1501
- rb_ext_ractor_safe(true);
1502
- #endif
1503
-
1504
- InitVM(pathname);
1505
-
1506
- rb_cPathname = rb_define_class("Pathname", rb_cObject);
1507
- rb_define_method(rb_cPathname, "initialize", path_initialize, 1);
1508
- rb_define_method(rb_cPathname, "freeze", path_freeze, 0);
1509
- rb_define_method(rb_cPathname, "==", path_eq, 1);
1510
- rb_define_method(rb_cPathname, "===", path_eq, 1);
1511
- rb_define_method(rb_cPathname, "eql?", path_eq, 1);
1512
- rb_define_method(rb_cPathname, "<=>", path_cmp, 1);
1513
- rb_define_method(rb_cPathname, "hash", path_hash, 0);
1514
- rb_define_method(rb_cPathname, "to_s", path_to_s, 0);
1515
- rb_define_method(rb_cPathname, "to_path", path_to_s, 0);
1516
- rb_define_method(rb_cPathname, "inspect", path_inspect, 0);
1517
- rb_define_method(rb_cPathname, "sub", path_sub, -1);
1518
- rb_define_method(rb_cPathname, "sub_ext", path_sub_ext, 1);
1519
- rb_define_method(rb_cPathname, "realpath", path_realpath, -1);
1520
- rb_define_method(rb_cPathname, "realdirpath", path_realdirpath, -1);
1521
- rb_define_method(rb_cPathname, "each_line", path_each_line, -1);
1522
- rb_define_method(rb_cPathname, "read", path_read, -1);
1523
- rb_define_method(rb_cPathname, "binread", path_binread, -1);
1524
- rb_define_method(rb_cPathname, "readlines", path_readlines, -1);
1525
- rb_define_method(rb_cPathname, "write", path_write, -1);
1526
- rb_define_method(rb_cPathname, "binwrite", path_binwrite, -1);
1527
- rb_define_method(rb_cPathname, "sysopen", path_sysopen, -1);
1528
- rb_define_method(rb_cPathname, "atime", path_atime, 0);
1529
- rb_define_method(rb_cPathname, "birthtime", path_birthtime, 0);
1530
- rb_define_method(rb_cPathname, "ctime", path_ctime, 0);
1531
- rb_define_method(rb_cPathname, "mtime", path_mtime, 0);
1532
- rb_define_method(rb_cPathname, "chmod", path_chmod, 1);
1533
- rb_define_method(rb_cPathname, "lchmod", path_lchmod, 1);
1534
- rb_define_method(rb_cPathname, "chown", path_chown, 2);
1535
- rb_define_method(rb_cPathname, "lchown", path_lchown, 2);
1536
- rb_define_method(rb_cPathname, "fnmatch", path_fnmatch, -1);
1537
- rb_define_method(rb_cPathname, "fnmatch?", path_fnmatch, -1);
1538
- rb_define_method(rb_cPathname, "ftype", path_ftype, 0);
1539
- rb_define_method(rb_cPathname, "make_link", path_make_link, 1);
1540
- rb_define_method(rb_cPathname, "open", path_open, -1);
1541
- rb_define_method(rb_cPathname, "readlink", path_readlink, 0);
1542
- rb_define_method(rb_cPathname, "rename", path_rename, 1);
1543
- rb_define_method(rb_cPathname, "stat", path_stat, 0);
1544
- rb_define_method(rb_cPathname, "lstat", path_lstat, 0);
1545
- rb_define_method(rb_cPathname, "make_symlink", path_make_symlink, 1);
1546
- rb_define_method(rb_cPathname, "truncate", path_truncate, 1);
1547
- rb_define_method(rb_cPathname, "utime", path_utime, 2);
1548
- rb_define_method(rb_cPathname, "lutime", path_lutime, 2);
1549
- rb_define_method(rb_cPathname, "basename", path_basename, -1);
1550
- rb_define_method(rb_cPathname, "dirname", path_dirname, 0);
1551
- rb_define_method(rb_cPathname, "extname", path_extname, 0);
1552
- rb_define_method(rb_cPathname, "expand_path", path_expand_path, -1);
1553
- rb_define_method(rb_cPathname, "split", path_split, 0);
1554
- rb_define_method(rb_cPathname, "blockdev?", path_blockdev_p, 0);
1555
- rb_define_method(rb_cPathname, "chardev?", path_chardev_p, 0);
1556
- rb_define_method(rb_cPathname, "executable?", path_executable_p, 0);
1557
- rb_define_method(rb_cPathname, "executable_real?", path_executable_real_p, 0);
1558
- rb_define_method(rb_cPathname, "exist?", path_exist_p, 0);
1559
- rb_define_method(rb_cPathname, "grpowned?", path_grpowned_p, 0);
1560
- rb_define_method(rb_cPathname, "directory?", path_directory_p, 0);
1561
- rb_define_method(rb_cPathname, "file?", path_file_p, 0);
1562
- rb_define_method(rb_cPathname, "pipe?", path_pipe_p, 0);
1563
- rb_define_method(rb_cPathname, "socket?", path_socket_p, 0);
1564
- rb_define_method(rb_cPathname, "owned?", path_owned_p, 0);
1565
- rb_define_method(rb_cPathname, "readable?", path_readable_p, 0);
1566
- rb_define_method(rb_cPathname, "world_readable?", path_world_readable_p, 0);
1567
- rb_define_method(rb_cPathname, "readable_real?", path_readable_real_p, 0);
1568
- rb_define_method(rb_cPathname, "setuid?", path_setuid_p, 0);
1569
- rb_define_method(rb_cPathname, "setgid?", path_setgid_p, 0);
1570
- rb_define_method(rb_cPathname, "size", path_size, 0);
1571
- rb_define_method(rb_cPathname, "size?", path_size_p, 0);
1572
- rb_define_method(rb_cPathname, "sticky?", path_sticky_p, 0);
1573
- rb_define_method(rb_cPathname, "symlink?", path_symlink_p, 0);
1574
- rb_define_method(rb_cPathname, "writable?", path_writable_p, 0);
1575
- rb_define_method(rb_cPathname, "world_writable?", path_world_writable_p, 0);
1576
- rb_define_method(rb_cPathname, "writable_real?", path_writable_real_p, 0);
1577
- rb_define_method(rb_cPathname, "zero?", path_zero_p, 0);
1578
- rb_define_method(rb_cPathname, "empty?", path_empty_p, 0);
1579
- rb_define_singleton_method(rb_cPathname, "glob", path_s_glob, -1);
1580
- rb_define_singleton_method(rb_cPathname, "getwd", path_s_getwd, 0);
1581
- rb_define_singleton_method(rb_cPathname, "pwd", path_s_getwd, 0);
1582
- rb_define_method(rb_cPathname, "glob", path_glob, -1);
1583
- rb_define_method(rb_cPathname, "entries", path_entries, 0);
1584
- rb_define_method(rb_cPathname, "mkdir", path_mkdir, -1);
1585
- rb_define_method(rb_cPathname, "rmdir", path_rmdir, 0);
1586
- rb_define_method(rb_cPathname, "opendir", path_opendir, 0);
1587
- rb_define_method(rb_cPathname, "each_entry", path_each_entry, 0);
1588
- rb_define_method(rb_cPathname, "unlink", path_unlink, 0);
1589
- rb_define_method(rb_cPathname, "delete", path_unlink, 0);
1590
- rb_undef_method(rb_cPathname, "=~");
1591
- rb_define_global_function("Pathname", path_f_pathname, 1);
102
+ rb_cPathname = rb_define_class("Pathname", rb_cObject);
103
+ rb_define_method(rb_cPathname, "<=>", path_cmp, 1);
104
+ rb_define_method(rb_cPathname, "sub", path_sub, -1);
1592
105
  }
1593
106
 
1594
107
  void
1595
- InitVM_pathname(void)
108
+ init_ids(void)
1596
109
  {
1597
110
  #undef rb_intern
1598
111
  id_at_path = rb_intern("@path");
1599
- id_to_path = rb_intern("to_path");
1600
- id_ENOTDIR = rb_intern("ENOTDIR");
1601
- id_atime = rb_intern("atime");
1602
- id_basename = rb_intern("basename");
1603
- id_base = rb_intern("base");
1604
- id_binread = rb_intern("binread");
1605
- id_binwrite = rb_intern("binwrite");
1606
- id_birthtime = rb_intern("birthtime");
1607
- id_blockdev_p = rb_intern("blockdev?");
1608
- id_chardev_p = rb_intern("chardev?");
1609
- id_chmod = rb_intern("chmod");
1610
- id_chown = rb_intern("chown");
1611
- id_ctime = rb_intern("ctime");
1612
- id_directory_p = rb_intern("directory?");
1613
- id_dirname = rb_intern("dirname");
1614
- id_empty_p = rb_intern("empty?");
1615
- id_entries = rb_intern("entries");
1616
- id_executable_p = rb_intern("executable?");
1617
- id_executable_real_p = rb_intern("executable_real?");
1618
- id_exist_p = rb_intern("exist?");
1619
- id_expand_path = rb_intern("expand_path");
1620
- id_extname = rb_intern("extname");
1621
- id_file_p = rb_intern("file?");
1622
- id_fnmatch = rb_intern("fnmatch");
1623
- id_foreach = rb_intern("foreach");
1624
- id_ftype = rb_intern("ftype");
1625
- id_getwd = rb_intern("getwd");
1626
- id_glob = rb_intern("glob");
1627
- id_grpowned_p = rb_intern("grpowned?");
1628
- id_lchmod = rb_intern("lchmod");
1629
- id_lchown = rb_intern("lchown");
1630
- id_link = rb_intern("link");
1631
- id_lstat = rb_intern("lstat");
1632
- id_lutime = rb_intern("lutime");
1633
- id_mkdir = rb_intern("mkdir");
1634
- id_mtime = rb_intern("mtime");
1635
- id_open = rb_intern("open");
1636
- id_owned_p = rb_intern("owned?");
1637
- id_pipe_p = rb_intern("pipe?");
1638
- id_read = rb_intern("read");
1639
- id_readable_p = rb_intern("readable?");
1640
- id_readable_real_p = rb_intern("readable_real?");
1641
- id_readlines = rb_intern("readlines");
1642
- id_readlink = rb_intern("readlink");
1643
- id_realdirpath = rb_intern("realdirpath");
1644
- id_realpath = rb_intern("realpath");
1645
- id_rename = rb_intern("rename");
1646
- id_rmdir = rb_intern("rmdir");
1647
- id_setgid_p = rb_intern("setgid?");
1648
- id_setuid_p = rb_intern("setuid?");
1649
- id_size = rb_intern("size");
1650
- id_size_p = rb_intern("size?");
1651
- id_socket_p = rb_intern("socket?");
1652
- id_split = rb_intern("split");
1653
- id_stat = rb_intern("stat");
1654
- id_sticky_p = rb_intern("sticky?");
1655
112
  id_sub = rb_intern("sub");
1656
- id_symlink = rb_intern("symlink");
1657
- id_symlink_p = rb_intern("symlink?");
1658
- id_sysopen = rb_intern("sysopen");
1659
- id_truncate = rb_intern("truncate");
1660
- id_unlink = rb_intern("unlink");
1661
- id_utime = rb_intern("utime");
1662
- id_world_readable_p = rb_intern("world_readable?");
1663
- id_world_writable_p = rb_intern("world_writable?");
1664
- id_writable_p = rb_intern("writable?");
1665
- id_writable_real_p = rb_intern("writable_real?");
1666
- id_write = rb_intern("write");
1667
- id_zero_p = rb_intern("zero?");
1668
113
  }