Added code to handle fcntl errors