- 论坛徽章:
- 0
|
#include "apue.h"
#include <fcntl.h>
int set_f1(int fd,int flags){
int val;
if((val=fcntl(fd,F_GETFL,0))<0){
printf("fcntl gettfl error\n");
exit(-1);
}
val |=flags;
if(fcntl(fd,F_SETFL,val)<0){
printf("fcntl F_SETFL error\n");
exit(-2);
}
}
int main (int argc,char *argv[])
{
int val;
int val1;
int fd;
// if(argc!=2){
// printf("usage:a.out <descriptor>\n");
// exit(-1);
//}
//fd=atoi(argv[1]);
if((fd=open("tt",O_RDWR | O_APPEND,FILE_MODE))<0){
printf("error creat\n");
exit(-1);
}
printf("fd:%d\n",fd);
set_f1(fd,O_SYNC);
// printf("fd:%s",atoi(argv[1]));
if((val=fcntl(fd,F_GETFL,0))<0){
printf("fcntl error for fd %d\n",atoi(argv[1]));
exit(-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("unknow access mode");
exit(-3);
}
}
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);
}
为什么输出是read write,append
而不是read write,append,synchronous writes
小弟实在 是不理解 望大家赐教 谢谢了
[ 本帖最后由 uid500 于 2008-9-12 16:12 编辑 ] |
|