日期:2014-05-16 浏览次数:20687 次
int main(int argc,char* argv[])
{
if(argc!=2){
puts("argc!=2");
return 1;
}
int val=fcntl(atoi(argv[1]),F_GETFL,0);
int accmode=val&O_ACCMODE;
switch(accmode){
case O_RDONLY:
puts("read only");
break;
case O_WRONLY:
puts("write only");
break;
case O_RDWR:
puts("read write");
break;
default:
puts("error");
break;
}
if(val&O_APPEND)puts("append");
if(val&O_NONBLOCK)puts("nonblock");
if(val&O_SYNC)puts("synchronous write");
putchar('\n');
return 0;
}
# ./a.out 0
read write
append
# tty
/dev/pts/0
# ./a.out 0 0< /dev/pts/0
read only