您的位置:首页 > 其它

对于指定的描述符打印文件标志

2016-12-23 21:28 274 查看
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int main(int argc,char * argv[]){
int val;
if(argc!=2){
printf("usage:a.out <descriptor#>");
}
if((val=fcntl(atoi(argv[1]),F_GETFL,0))<0){
printf("fcntl error for fd %d",atoi(argv[1]));
}
switch(val &O_ACCMODE){
case O_RDONLY:
printf("read only");
break;

case O_WRONLY:
printf("write only");
break;

case O_RDWR:
printf("read write");
break;

default :
printf("unknown access mode");
}

if (val & O_APPEND){
printf(",append");
}
if(val & O_NONBLOCK){
printf(",nonblocking");
}

#if defined(O_SYNC)
if(val & O_SYNC)
printf(",synchronous writes");
#endif
#if !defined(_POSIX_C_SOURCE) && defined(O_FSYNC)
if(val & O_FSYNC)
printf(",synchronous writes")
#endif
putchar('\n');
exit(0);
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: