您的位置:首页 > 其它

程序3-5 对一个文件描述符打开一个或多个文件状态标志

2014-04-25 22:09 239 查看
//http://blog.chinaunix.net/uid-24549279-id-71355.html
/*
============================================================================
Name        : test.c
Author      : blank
Version     :
Copyright   : Your copyright notice
Description : 程序3-5 对一个文件描述符打开一个或多个文件状态标志
============================================================================
*/

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include "ourhdr.h"

/*
* flags are file status flags to turn on
*/
void set_f1(int fd, int flags){
int val;

if ((val = fcntl(fd, F_GETFD, 0)) < 0){
err_sys("fcntl F_GETFD error\n");
}

// turn on
val |= flags;

if (fcntl(fd, F_SETFD, val) < 0){
err_quit("fcntl F_SETFL error\n");
}
}

/*
* flags are file status flags to turn off
*/
void del_f1(int fd, int flags){
int val;

if ((val = fcntl(fd, F_GETFD, 0)) < 0){
err_sys("fcntl F_GETFD error\n");
}

// turn off
val &= ~flags;

if (fcntl(fd, F_SETFD, val) < 0){
err_quit("fcntl F_SETFL error\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐