0
int main(int argc, char *argv[])
{
int i, j, count;
int f1;
char buf[16];
f1 = open(argv[1], O_RDWR | O_APPEND);
if(f1 == -1)
perror("open failed");
if(lseek(f1, 0, SEEK_SET) == -1)
printf("lseek failed\n");
while(count = read(0, buf, 16)) {
write(f1, buf, count);
}
close(f1);
return 0;
}
這是我的代碼。它打開作爲參數給出的文件,並且應該在文件開始時從控制檯寫入所有文件。該文件中追加模式打開,然後lseek的用來描述符移動到開始。 f1的值沒有變化,不會打印lseek失敗。lseek不能使用文件的追加模式