linux编程fcntl获取和设置文件状态
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h> #define ERR_EXIT( m ) \
do \
{ \
perror( m ); \
exit( EXIT_FAILURE ); \
}while( 0 ) //设置某个文件状态
void set_flag( int fd, int flags );
//清除某个文件状态
void clear_flag( int fd, int flags ); int main( int argc, char* argv[] ) { char buf[64] = { 0 };
int nread; //设置非阻塞状态
set_flag( 0, O_NONBLOCK );
//清除非阻塞状态, 读取标准输入又变成阻塞
clear_flag( 0, O_NONBLOCK );
nread = read( 0, buf, 64 );
if( -1 == nread ) {
ERR_EXIT( "获取输入失败" );
}
printf( "buf=%s\n", buf ); return 0;
} void set_flag( int fd, int flags ) {
int oldflag;
oldflag = fcntl( fd, F_GETFL, 0 );
if( -1 == oldflag ) {
ERR_EXIT( "获取原来的状态失败" );
} oldflag = oldflag | flags;
int ret = fcntl( fd, F_SETFL, oldflag );
if( -1 == ret ) {
ERR_EXIT( "设置新的文件状态失败" );
}
} void clear_flag( int fd, int flags ) {
int oldflag;
oldflag = fcntl( fd, F_GETFL, 0 );
if( -1 == oldflag ) {
ERR_EXIT( "获取原来的状态失败" );
}
oldflag = oldflag & ~flags;
int ret = fcntl( fd, F_SETFL, oldflag );
if( -1 == ret ) {
ERR_EXIT( "设置新的文件状态失败" );
}
}
linux编程fcntl获取和设置文件状态的更多相关文章
- linux编程fcntl获取和设置文件锁
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types. ...
- 第七篇:使用 fcntl 函数 获取,设置文件的状态标志
前言 当打开一个文件的时候,我们需要指定打开文件的模式( 只读,只写等 ).那么在程序中如何获取,修改这个文件的状态标志呢? 本文将告诉你如何用 fcntl函数 获取指定文件的状态标志. 解决思路 1 ...
- 使用 fcntl 函数 获取,设置文件的状态标志
前言 当打开一个文件的时候,我们需要指定打开文件的模式( 只读,只写等 ).那么在程序中如何获取,修改这个文件的状态标志呢?本文将告诉你如何用 fcntl函数 获取指定文件的状态标志. 解决思路 1. ...
- fcntl获取和修改文件打开状态标志
[root@bogon code]# cat b.c #include<stdio.h> #include<error.h> #include<unistd.h> ...
- linux下对普通用户设置文件访问控命令之setfacl
命令名 setfacl -设置文件访问控制列表 常用用法:setfacl [-bkRd] [{-m|-x} acl参数] 目标文件名 命令的常用参数 -m 设置后续的acl参数给文件使用(常用). ...
- LinuxShell脚本编程基础5--数值,字符串,文件状态测试,((..))和[[..]]的使用
1.数值比较 ! /bin/bash echo "enter a score:" read num1 ] then echo "Very Good" elif ...
- Linux 编程学习笔记----ANSI C 文件I/O管理
转载请注明出处:http://blog.csdn.net/suool/article/details/38129201 问题引入 文件的种类 依据数据存储的方式不同,能够将文件分为文本文件和二进制文件 ...
- TDirectory.GetCreationTime、TDirectory.SetCreationTime获取和设置文件夹创建时间
使用函数: System.IOUtils.TDirectory.GetCreationTime//获取创建时间 System.IOUtils.TDirectory.SetCreationTime//设 ...
- TDirectory.GetAttributes、TDirectory.SetAttributes获取和设置文件夹属性
使用函数: System.IOUtils.TDirectory.GetAttributes//获取属性 System.IOUtils.TDirectory.SetAttributes//设置属性 注: ...
随机推荐
- delphi使用Foxit Quick PDF Library读写pdf文本和图片
简介: Debenu Quick PDF Library(PDF编程开发工具)提供一套全方位的 PDF API 函数,帮助您快速简便地处理 PDF 文件.从文档属性的基本操作到创建您自己的 PDF 查 ...
- JS---DOM---tab切换案例实现---排他
tab切换案例实现 <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...
- English: Class Speed
Xx_Introduce https://www.jianshu.com/p/d1c1b84d89e8 Please protection,respect,love,"China's Int ...
- Linux基础命令---ntpstat显示时间服务器同步
ntpstat ntpstat指令用于显示本机上一次和服务器同步时间的情况. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora. 1.语法 ntpstat 2 ...
- CentOS7 如何升级Git
CentOS7自带的git版本1.8.3.1,这个版本有点低了.于是决定折腾升级,我首先想到的是用update更新: yum update git 结果,事与原违,还是1.8.3.1.在网上提供的升级 ...
- Community structure enhanced cascade prediction 笔记
目录 一.摘要 二.杂记 三.模型思想 四.实验 五.其他 六.参考文献 一.摘要 深度学习不用去手工提取特征,但是现有深度模型没有在传播预测任务中使用社区结构.所以提出一个CS-RNN框架,把社区在 ...
- 正确设置越狱版ios的终端编码--命令行中文的处理
本文是针对越狱版iPhone手机的,手机没有越狱就别看了,看了也没办法用. 越狱版的iPhone当然是为了跟电脑一样做各种有趣的事情的. 但通常越狱的iPhone在命令行都无法处理中文,比如你的播放器 ...
- cookie、localStorage 和 sessionStorage 的使用以及区别
localStorage 和 sessionStorage 的增删改查: 存储数据: sessionStorage.setItem('key', 'sessionStorage的值'); // 存储数 ...
- A:linux基础章节导航
本章的内容主要有: 模板机的安装 常用的小命令 find awk vim sed
- 计算机网络知识之TCP/IP协议簇
OSI参考模型 OSI的来源 OSI(Open System Interconnect),即开放式系统互联. 一般都叫OSI参考模型,是ISO(国际标准化组织)组织在1985年研究的网 ...