#include#include #include #include int main(int argc, char *argv[]) { int fd = open("a.txt", O_RDWR); char buf[12138] = {0}; // 此时再写入就是追加写入了 read(fd, buf, 12138); printf("原始内容:%sn", buf); // 获取原始flag并加上O_APPEND flag int flag = fcntl(fd, F_GETFL) | O_APPEND; // 设置flag fcntl(fd, F_SETFL, flag); char* str = "tafter append"; // 此时再写入就是追加写入了 write(fd, str, strlen(str)); close(fd); fd = open("a.txt", O_RDWR); read(fd, buf, 12138); printf("追加后的内容:%sn", buf); return 0; }



