#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main()
{
int fd;
char *buf=“cao kuangyuan hen shuai!”;
fd = open("./file1",O_RDWR);
if(fd == -1){
printf(“open file1 failed\n”);
fd = open("./file1",O_RDWR|O_CREAT,0600);
if(fd>0){
printf("creat file1 success!\n");
}
}
printf("open success : fd = %d\n",fd);
//ssize_t write(int fd, const void *buf, size_t count);
write(fd,buf,strlen(buf));
close(fd);
return 0;
}