linux fcntl-取消设置标志 [英] linux fcntl - unsetting flag

查看:150
本文介绍了linux fcntl-取消设置标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用fcntl取消设置已设置的标志?

How do i unset a already set flag using fcntl?

例如我可以使用

fcntl(sockfd, F_SETFL, flags | O_NONBLOCK)

现在,我想取消设置O_NONBLOCK标志.

Now, i want to unset the O_NONBLOCK flag.

我尝试了fcntl(sockfd,F_SETFL,标志|〜O_NONBLOCK).它给我错误EINVAL

I tried fcntl(sockfd, F_SETFL, flags | ~O_NONBLOCK). It gave me error EINVAL

推荐答案

int oldfl;
oldfl = fcntl(sockfd, F_GETFL);
if (oldfl == -1) {
    /* handle error */
}
fcntl(sockfd, F_SETFL, oldfl & ~O_NONBLOCK);

未经测试,但希望能有所帮助. :-)

Untested, but hope this helps. :-)

这篇关于linux fcntl-取消设置标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆