Add an fcntl F_GET/SET_EX and clean up some redundant test code.

First part of #526.