打开写的.c文件
内容为
代码
<sys/stat.h>
#include <fcntl.h>
#include<stdio.h>
#include<unistd.h>
#include<string.h>//off_t lseek(int fd, off_t offset, int whence);
//int open(const char *pathname, int flags);
//int open(const char *pathname, int flags, mode_t mode);
//ssize_t write(int fd, const void *buf, size_t count);
//ssize_t read(int fd, void *buf, size_t count);
#define filename "mm"
#define writeNum 128
#define readNum 12
int main()
{int offset;int fd;char writeBuff[writeNum] = {0};char readBuff[readNum] = {0};char *test = "hello world";if(writeNum<(strlen(test)+1)){printf("error:writeBuff less than test\n");return -1;}strcpy(writeBuff,test);fd = open("mm",O_APPEND|O_RDWR|O_CREAT,0755);if(fd == -1){printf("open failed!");perror("why");return -1;}printf("open successed!");// offset = lseek(fd,1,SEEK_CUR);printf("offset is %d\n",offset);write(fd,&writeBuff[0],11);
// read(fd,&readBuff,1);
// printf("%s \n",readBuff);close(fd);return 0;}
每编译一次,cat一次,会在末尾append一次 hello world