Skip to content

Commit

Permalink
Refactor IO.setup and avoid fcntl syscall when mode is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Jan 13, 2025
1 parent 294b338 commit 90816ee
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/ruby/truffleruby/core/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -817,17 +817,17 @@ def self.sysopen(path, mode = nil, perm = nil)
#
# The +sync+ attribute will also be set.
def self.setup(io, fd, mode, sync)
if !Truffle::Boot.preinitializing? && Truffle::POSIX::NATIVE
cur_mode = Truffle::POSIX.fcntl(fd, F_GETFL, 0)
Errno.handle if cur_mode < 0
cur_mode &= ACCMODE
end
raise Errno::EBADF if fd < 0

if mode
mode = Truffle::IOOperations.parse_mode(mode)
mode &= ACCMODE
elsif !Truffle::Boot.preinitializing? && Truffle::POSIX::NATIVE
mode = Truffle::POSIX.fcntl(fd, F_GETFL, 0)
Errno.handle if mode < 0
mode &= ACCMODE
else
mode = cur_mode or raise 'No mode given for IO'
raise 'No mode given for IO'
end

# Close old descriptor if there was already one associated
Expand Down

0 comments on commit 90816ee

Please sign in to comment.