- 论坛徽章:
- 0
|
书上3.13节有这么一段程序:
程序3-4 对于指定的描述符打印文件标志
#include <sys/types.h>
#include <fcntl.h>
#include “ourhdr.h”
int main(int argc,char* argv[])
{
int accmode,val;
if(argc!=2)
err_quit(“Usage: a.out <descriptor#>”);
if((val=fcntl(atoi(argv[1]),F_GETFL,0))<0)
err_sys(“fcntl error for fd %d”,atoi(argv[1]));
accmode=val&O_ACCMODE;
if(accmode==O_RDONLY)
printf(“read only”);
else if(accmode==O_WRONLY)
printf(“write only”);
else if(accmode==O_RDWR)
printf(“read write”);
else err_dump(“unknown access mode”);
if(val&O_APPEND) printf(“,append”);
if(val&O_NONBLOCK) printf(“,nonblocking”);
#if !defined(_POSIX_SOURCE)&&defined(O_SYNC)
if(val&O_SYNC) printf(“,synchronous writes”);
#endif
putchar(“\n”)
exit(0);
}
注释:
(1)运行结果:
a.out 0 < /dev/tty
read only
a.out 1 > temp.foo
cat temp.foo
write only
a.out 2 2>>temp.foo
write only,append
a.out 5 5<>temp.foo
read write
程序指定的命令参数是2个
可 a.out 0 < /dev/tty 和a.out 2 2>>temp.foo意思是??参数4个??
a.out 1 > temp.foo的意思我倒明白,是把命令a.out 1的结果放到文件temp.foo里面去。
还有,_POSIX_SOURCE宏到底有什么用处阿??那书上第二章说了,但整个那一章就基本上完全看不明白。。。 |
|