linux fcntl - unsetting flag
问题 How do i unset a already set flag using fcntl? For e.g. I can set the socket to nonblocking mode using fcntl(sockfd, F_SETFL, flags | O_NONBLOCK) Now, i want to unset the O_NONBLOCK flag. I tried fcntl(sockfd, F_SETFL, flags | ~O_NONBLOCK). It gave me error EINVAL 回答1: int oldfl; oldfl = fcntl(sockfd, F_GETFL); if (oldfl == -1) { /* handle error */ } fcntl(sockfd, F_SETFL, oldfl & ~O_NONBLOCK); Untested, but hope this helps. :-) 回答2: val = fcntl(fd, F_GETFL, 0); flags = O_NONBLOCK; val &=