Try using POSIX fcntl instead of ioctl. Let's see what mingw thinks of this.