文件I/O-008.fcntl返回文件标志并解析打印标志

来源:互联网 发布:淘宝商家客服投诉电话 编辑:程序博客网 时间:2024/06/06 19:15
/*fcntl()返回文件标志并解析打印文件标志*/#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <string.h>int main(int argc,char const *argv[]){    int val;val=fcntl(atoi(argv[1]),F_GETFL,0);if(val == -1){    printf("fcntl erro\n");}switch(val & O_ACCMODE)//O_ACCMODE  003{case O_RDONLY:printf("read only");break;//O_RDONLY 000case O_WRONLY:printf("read only");break;//O_WRONLY 001case O_RDWR:printf("read only");break;//O_RDWR  002default:printf("unknown access mode");}if(val & O_APPEND)//O_APPEND  2000{    printf(",append");}if(val & O_NONBLOCK)//O_NONBLOCK   4000{    printf(",nonblock");}putchar('\n');exit(0);}/*./a.out 0read only./a.out 2read only./a.out 1read only./a.out 0 < /dev/ttyread only./a.out 1 > temp.foocat temp.fooread only./a.out 2 2>>temp.fooread only,append./a.out 5 5<>temp.fooread only*/

0 0