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 파일 추가 모드로 작동하지 않습니다