#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc,char* argv[])
{
int fd = 0;
int flag = 0;
fd = open("a.txt",O_WRONLY | O_APPEND);//读写追加打开
if(fd < 0)
{
printf("open %s failed\n","a.txt");
return 1;
}
flag = fcntl(fd,F_GETFL,0);//获取文件状态
flag = flag & (~O_APPEND);//取消追加功能
fcntl(fd,F_SETFL,flag);//设置文件描述符状态
write(fd,"Hello World",strlen("Hello World"));
close(fd);
return 0;
}