Код: Выделить всё
mp:projects-20:17:09-$ ./lseek_demo
The end offset of file1 is 1268
The start offset of file2 is 0
Diff between them is -1268
The mem address of file1 is 0x7ffce008e738
The mem address of file2 is 0x7ffce008e740
mp:projects-20:17:12-$ ./lseek_demo
The end offset of file1 is 1268
The start offset of file2 is 0
Diff between them is -1268
The mem address of file1 is 0x7fff9113e148
The mem address of file2 is 0x7fff9113e150
Код: Выделить всё
#include
#include
#include
#include
void offsets(const char* fname1,const char* fname2)
{
int fd0 = open(fname1, O_RDWR);
int fd1 = open(fname2, O_RDWR);
if (fd0 == -1 || fd1 == -1)
perror("opne");
off_t off_fd0 = lseek(fd0, -1, SEEK_END);
off_t off_fd1 = lseek(fd1,0,SEEK_SET);
close(fd0);
close(fd1);
printf ("The end offset of file1 is %ld\n The start offset of file3 is %ld\n Diff between them is %ld\n",off_fd0, off_fd1,(off_fd1 - off_fd0));
printf ("The mem address of file1 is %p\n The mem address of file2 is %p\n",&off_fd0,&off_fd1);
}
int main()
{
offsets ("readme.txt","slack_space_calc.c");
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... h-time-i-l