Search code examples
clseek

Why isn't lseek changing value? (C)


unsigned int file = open(argv[1], O_RDONLY);

printf("%u\n", file);
printf("%u\n", elf.offset);

lseek(file, elf.offset, SEEK_SET);

printf("%u", file);

OutPut:

3
52
3

Shouldn't file be set to 52?


Solution

  • Upon successful completion, the resulting offset, as measured in bytes from the beginning of the file, shall be returned.

    try this printf("lseek_offset: %d\n", lseek(file, elf.offset, SEEK_SET));