Centralise calls to fcntl into functions that carefully check the