Better ioctl test on error condition (errno should be set and err return as -1)