@@ -337,7 +337,7 @@ def self.binwrite(file, string, offset = nil, **options)
337
337
default_mode = File ::CREAT | File ::RDWR | File ::BINARY
338
338
default_mode |= File ::TRUNC unless offset
339
339
340
- mode , _binary , external , _internal , _autoclose , perm = IO . normalize_options ( nil , nil , options , default_mode )
340
+ mode , _binary , external , _internal , _autoclose , perm = Truffle :: IOOperations . normalize_options ( nil , nil , options , default_mode )
341
341
342
342
File . open ( file , mode , encoding : ( external || 'ASCII-8BIT' ) , perm : perm ) do |f |
343
343
f . seek ( offset ) if offset
@@ -502,7 +502,7 @@ def self.write(file, string, offset = nil, **options)
502
502
default_mode = File ::CREAT | File ::WRONLY
503
503
default_mode |= File ::TRUNC unless offset
504
504
505
- mode , _binary , external , _internal , _autoclose , perm = IO . normalize_options ( nil , nil , options , default_mode )
505
+ mode , _binary , external , _internal , _autoclose , perm = Truffle :: IOOperations . normalize_options ( nil , nil , options , default_mode )
506
506
507
507
open_args = [ mode ]
508
508
open_kw = { encoding : ( external || 'ASCII-8BIT' ) , perm : perm }
@@ -569,99 +569,6 @@ def self.try_convert(obj)
569
569
Truffle ::Type . rb_check_convert_type obj , IO , :to_io
570
570
end
571
571
572
- def self . normalize_options ( mode , perm , options , default_mode = nil )
573
- autoclose = true
574
-
575
- if mode
576
- mode = ( Truffle ::Type . try_convert ( mode , Integer , :to_int ) or
577
- Truffle ::Type . coerce_to ( mode , String , :to_str ) )
578
- end
579
-
580
- if options
581
- if optmode = options [ :mode ]
582
- optmode = ( Truffle ::Type . try_convert ( optmode , Integer , :to_int ) or
583
- Truffle ::Type . coerce_to ( optmode , String , :to_str ) )
584
- end
585
-
586
- if mode && optmode
587
- raise ArgumentError , 'mode specified twice'
588
- end
589
-
590
- mode ||= optmode
591
- mode ||= default_mode
592
-
593
- if flags = options [ :flags ]
594
- flags = Truffle ::Type . rb_convert_type ( flags , Integer , :to_int )
595
-
596
- if Primitive . nil? ( mode )
597
- mode = flags
598
- elsif Primitive . is_a? ( mode , Integer )
599
- mode |= flags
600
- else # it's a String
601
- mode = Truffle ::IOOperations . parse_mode ( mode )
602
- mode |= flags
603
- end
604
- end
605
-
606
- if optperm = options [ :perm ]
607
- optperm = Truffle ::Type . try_convert ( optperm , Integer , :to_int )
608
- end
609
-
610
- if perm
611
- raise ArgumentError , 'perm specified twice' if optperm
612
- else
613
- perm = optperm
614
- end
615
-
616
- autoclose = Primitive . as_boolean ( options [ :autoclose ] ) if options . key? ( :autoclose )
617
- end
618
-
619
- mode ||= default_mode
620
-
621
- if Primitive . is_a? ( mode , String )
622
- mode , external , internal = mode . split ( ':' , 3 )
623
- raise ArgumentError , 'invalid access mode' unless mode
624
-
625
- binary = true if mode . include? ( ?b)
626
- binary = false if mode . include? ( ?t)
627
- elsif mode
628
- binary = true if ( mode & BINARY ) != 0
629
- end
630
-
631
- if options
632
- if options [ :textmode ] and options [ :binmode ]
633
- raise ArgumentError , 'both textmode and binmode specified'
634
- end
635
-
636
- if Primitive . nil? binary
637
- binary = options [ :binmode ]
638
- elsif options . key? ( :textmode ) or options . key? ( :binmode )
639
- raise ArgumentError , 'text/binary mode specified twice'
640
- end
641
-
642
- if !external and !internal
643
- external = options [ :external_encoding ]
644
- internal = options [ :internal_encoding ]
645
- elsif options [ :external_encoding ] or options [ :internal_encoding ] or options [ :encoding ]
646
- raise ArgumentError , 'encoding specified twice'
647
- end
648
-
649
- if !external and !internal
650
- encoding = options [ :encoding ]
651
-
652
- if Primitive . is_a? ( encoding , Encoding )
653
- external = encoding
654
- elsif !Primitive . nil? ( encoding )
655
- encoding = StringValue ( encoding )
656
- external , internal = encoding . split ( ':' , 2 )
657
- end
658
- end
659
- end
660
- external = Encoding ::BINARY if binary and !external and !internal
661
- perm ||= 0666
662
- [ mode , binary , external , internal , autoclose , perm ]
663
- end
664
-
665
572
def self . open ( *args , **options )
666
573
io = new ( *args , **options )
667
574
@@ -720,7 +627,7 @@ def self.popen(*args)
720
627
end
721
628
end
722
629
723
- mode , binary , external , internal , _autoclose , _perm = IO . normalize_options ( mode , nil , io_options )
630
+ mode , binary , external , internal , _autoclose , _perm = Truffle :: IOOperations . normalize_options ( mode , nil , io_options )
724
631
mode_int = Truffle ::IOOperations . parse_mode mode
725
632
726
633
readable = false
@@ -941,7 +848,7 @@ def initialize(fd, mode = nil, **options)
941
848
@external = nil
942
849
@pid = nil
943
850
944
- mode , binary , external , internal , autoclose_tmp , _perm = IO . normalize_options ( mode , nil , options )
851
+ mode , binary , external , internal , autoclose_tmp , _perm = Truffle :: IOOperations . normalize_options ( mode , nil , options )
945
852
946
853
fd = Truffle ::Type . coerce_to ( fd , Integer , :to_int )
947
854
sync = fd == 2 # stderr is always unbuffered, see setvbuf(3)
0 commit comments