O_RDWR is not read-only, so testing this will not suffice:
"check readonly by trying to open the file for writing"

You need to see if bit 0 is set in the perm mask.