#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
int main
{
int fd;
fd = open("./file1",O_RDWR|O_CREAT|O_EXCL);
if(fd == -1){
printf("文件已经创建\n");
}
int fd2
char *buf = "longhaiyanghenshuai!";
fd2 = open("./file1",O_RDWR|O_APPEND);
int n_write = write(fd2,buf,strlen(buf));
printf("write %d byte to file1,context:%s\n",n_write,buf);
close(fd2);
int fd3;
char *buf = "test";
fd3 = open("./file1",O_RDWR|O_TRUNC);
int n_write = write(fd,buf,strlen(buf));
printf("write %d byte to file1,context:%s\n",n_write,buf);
close(fd3);
int fd4;
fd4 = creat("./longhaiyang",S_IRWXU);
return 0;
}```