1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
int valider(char * f, cle p)
{
hash h;
signature s;
FILE * stream = fopen(f, "r");
if(!stream){
fprintf(stderr, "Erreur : impossible d'ouvrir %s en lecture.\n", f);
return -1;
}
h = calculerHash(stream);
...
}
hash calculerHash(FILE * f)
{
hash h = malloc(sizeof(char)*17);
long s = fsize(f);
char * str = malloc(sizeof(char) * (s+1));
char * save = str;
int lu = 1024, lire = 1024, tlu = 0;
while(lu == lire){
lu = fread(str, sizeof(char), lire, f);
tlu += lu;
str += lu;
}
if(tlu != s){
fprintf(stderr, "Erreur lors de la lecture du programme.\n");
return NULL;
}
save[s] = '\0';
hasher(save, h);
return h;
} |