This is implemented so that if opening with O_RDRW is failing, `file_readonly` gets set to `TRUE`.
With this 'trick' we can avoid a race condition (http://en.wikipedia.org/wiki/Time_of_check_to_time_of_use) and an extra call to check the perm mask. Maybe I should make this code cleaner and add a comment to describe this.