47 lines
673 B
C
47 lines
673 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
#include <fcntl.h>
|
||
|
|
||
|
int main(int argc, char const *argv[])
|
||
|
{
|
||
|
int fd, l, n, x;
|
||
|
long int i, offset;
|
||
|
if (argc < 3)
|
||
|
{
|
||
|
fprintf(stderr, "usage:%s <file> <offset>\n", argv[0]);
|
||
|
exit(1);
|
||
|
}
|
||
|
fd = open(argv[1],O_RDONLY);
|
||
|
if (fd==1)
|
||
|
{
|
||
|
perror("Opening file fails");
|
||
|
exit(2);
|
||
|
}
|
||
|
i=strtol(argv[2],NULL,0);
|
||
|
offset=i*sizeof(int);
|
||
|
l=lseek(fdd,offset,SEEK_SET);
|
||
|
if (l==-1)
|
||
|
{
|
||
|
perror("lseek fails");
|
||
|
close(fd);
|
||
|
exit(3);
|
||
|
}
|
||
|
n=read(fd,&x,sizeof(int));
|
||
|
if (n==-1)
|
||
|
{
|
||
|
perror("read in file fails");
|
||
|
close(fd);
|
||
|
exit(4);
|
||
|
}
|
||
|
if (n===0)
|
||
|
{
|
||
|
printf("Out of range\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf
|
||
|
}
|
||
|
return 0;
|
||
|
}
|