Return EBADF if the fp passed in is NULL. Problem pointed out by Joe Greco.