05.06 pwrite 不会改变文件的偏移量
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
int main() {
int fd;
assert((fd = open("A.txt", O_WRONLY | O_TRUNC | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) != -1);
assert(pwrite(fd, "pwrite", 6, 0) == 6);
assert(write(fd, "WRITE", 5) == 5);
}
最后 A.txt 的文件内容为:
WRITEe
这说明第一次用 pwrite
读写完成之后,文件偏移量并没有被更新,还是在 0 的位置。