# _arg[1]_ :: モードの指定。例 : w:utf-8(書き込みモード・UTF-8エンコードでファイルを開く)
def myopen(*arg)
mode = arg[1]
- arg[1] = mode[/[^:]+/] if mode && RUBY_VERSION < "1.8.7" && mode.include?(':')
+ rdonly_p = true
+ case mode
+ when String
+ arg[1] = mode[/[^:]+/] if RUBY_VERSION < "1.8.7" && mode.include?(':')
+ rdonly_p = /\A[^:]*[wa+]/ !~ mode
+ when Numeric
+ rdonly_p = !(mode & (IO::WRONY | IO::RDWR))
+ end
open(*arg) do |f|
- f.flock(/\A\w+r/ =~ mode ? File::LOCK_SH : File::LOCK_EX)
+ f.flock(rdonly_p ? File::LOCK_SH : File::LOCK_EX)
return yield(f)
end
end
# _arg[1]_ :: モードの指定。例 : w:utf-8(書き込みモード・UTF-8エンコードでファイルを開く)
def myopen(*arg)
mode = arg[1]
- arg[1] = mode[/[^:]+/] if mode && RUBY_VERSION < "1.8.7" && mode.include?(':')
+ rdonly_p = true
+ case mode
+ when String
+ arg[1] = mode[/[^:]+/] if RUBY_VERSION < "1.8.7" && mode.include?(':')
+ rdonly_p = /\A[^:]*[wa+]/ !~ mode
+ when Numeric
+ rdonly_p = !(mode & (IO::WRONY | IO::RDWR))
+ end
open(*arg) do |f|
- f.flock(/\A\w+r/ =~ mode ? File::LOCK_SH : File::LOCK_EX)
+ f.flock(rdonly_p ? File::LOCK_SH : File::LOCK_EX)
return yield(f)
end
end