36 lines
877 B
C
36 lines
877 B
C
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<fcntl.h>
|
|
#include<unistd.h>
|
|
#include<string.h>
|
|
|
|
int main(int argc, char* argv[]) {
|
|
int f,n;
|
|
unsigned int x;
|
|
unsigned long int i, offset, l;
|
|
memset(tst,0,256);
|
|
if(argc<4){
|
|
printf("erreur : %s <file_name> <32-bit int in Hex> <Offset in Hex>\n",argv[0]);
|
|
exit(1);
|
|
}
|
|
f=open(argv[1],O_WRONLY);
|
|
if(f==-1){
|
|
perror("Opening failed");
|
|
exit(2);
|
|
}
|
|
x= (unsigned int)strtol(argv[2],NULL,16);
|
|
i= (unsigned int)strtol(argv[3],NULL,16);
|
|
offset = i*sizeof(int);
|
|
l=lseek(f,0,SEEK_END);
|
|
if (offset > l) offset =l;
|
|
l=lseek(f,offset,SEEK_SET);
|
|
if(l==-1){
|
|
perror("erreur dans lseek");
|
|
exit(2);
|
|
}
|
|
ents = strtol(argv[2],NULL,16);
|
|
write(f,&x,sizeof(int));
|
|
close(f);
|
|
return EXIT_SUCCESS;
|
|
}
|