'bad file descriptor' bug on mac

OpenFile occurs'bad file descriptor' error on my mac without os.O_RDWR flag. So I try to fix it.
But I don't test it on Linux. So I don't know whether it could work well on Linux.