From: Tanaka Akira Date: 2004-12-06T16:08:29+09:00 Subject: Re: Obtaining mode information on a File object In article <20041204195115.GA83981@lizzy.catnook.com>, Jos Backus writes: > Another question... How do I access the File open mode ("w" in this case) on a > File object? Example: % ruby -rfcntl -e ' open("/dev/null") {|f| p f.fcntl(Fcntl::F_GETFL) & Fcntl::O_ACCMODE } open("/dev/null", "w") {|f| p f.fcntl(Fcntl::F_GETFL) & Fcntl::O_ACCMODE } open("/dev/null", "r+") {|f| p f.fcntl(Fcntl::F_GETFL) & Fcntl::O_ACCMODE } ' 0 1 2 0 means O_RDONLY. 1 means O_WRONLY. 2 means O_RDWR. I don't know this is portable enough. Note that this doesn't work for duplex pipe. % ruby -rfcntl -e ' open("|echo", "r+") {|f| p f.fcntl(Fcntl::F_GETFL) & Fcntl::O_ACCMODE } ' 0 -- Tanaka Akira