44 lines
864 B
C
44 lines
864 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <unistd.h>
|
||
|
#include <string.h>
|
||
|
#define STDOUT 1
|
||
|
#define STDERR 2
|
||
|
#define SZBUF 256
|
||
|
|
||
|
|
||
|
int main(int argc, char** argv){
|
||
|
int descripteur, curseur, nb;
|
||
|
long int offset, i;
|
||
|
char buf[SZBUF];
|
||
|
|
||
|
if (argc < 2){
|
||
|
fprintf(stderr, "Usage : %s <file-name>\n",argv[0]);
|
||
|
exit(1);
|
||
|
}
|
||
|
descripteur = open(argv[1], O_RDONLY);
|
||
|
if (descripteur==-1){
|
||
|
perror("opening file fail !");
|
||
|
exit(2);
|
||
|
}
|
||
|
i = strtol(argv[2],NULL,0);
|
||
|
offset = i*4;
|
||
|
curseur = lseek(descripteur, offset, SEEK_SET);
|
||
|
if (curseur == -1){
|
||
|
perror("lseek fail");
|
||
|
exit(3);
|
||
|
}
|
||
|
nb = read(descripteur,&x,4);
|
||
|
if (nb == -1){
|
||
|
perror("Read in file fail");
|
||
|
exit(4);
|
||
|
}
|
||
|
if (nb == 0){
|
||
|
perror("out of range");
|
||
|
exit(5);
|
||
|
}
|
||
|
printf("The number at offset %d is 0x%08x --> %d\n",i,x,x);
|
||
|
exit(0);
|
||
|
}
|