--- rpl/rplsums/rplsum.c 2010/03/04 18:30:46 1.1 +++ rpl/rplsums/rplsum.c 2017/06/28 09:20:29 1.12 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.0.12 - Copyright (C) 1989-2010 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.27 + Copyright (C) 1989-2017 Dr. BERTRAND Joël This file is part of RPL/2. @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) { - EVP_MD_CTX contexte; + EVP_MD_CTX *contexte; int in_fd; @@ -58,6 +58,8 @@ main(int argc, char *argv[]) if (stat(fichier, &stat_buf) != 0) { + fprintf(stderr, "stat() failed\n"); + perror("stat"); exit(EXIT_FAILURE); } @@ -65,46 +67,72 @@ main(int argc, char *argv[]) if ((chaine = malloc(taille_fichier)) == NULL) { + fprintf(stderr, "malloc() failed\n"); exit(EXIT_FAILURE); } if ((in_fd = open(fichier, 0, O_RDONLY)) < 0) { + fprintf(stderr, "open() failed\n"); + perror("open"); free(chaine); exit(EXIT_FAILURE); } if ((octets_lus = read(in_fd, chaine, taille_fichier)) != taille_fichier) { +# ifndef OS2 + // Sur des fichiers binaires et sous OS/2, le nombre d'octets lus peut + // être inférieur à la taille du fichier sur le disque. + + fprintf(stderr, "read() failed\n"); + fprintf(stderr, "Meditation: %d < %d\n", (int) octets_lus, + (int) taille_fichier); + perror("read"); close(in_fd); free(chaine); exit(EXIT_FAILURE); +# endif } close(in_fd); - if (EVP_DigestInit(&contexte, EVP_sum()) != 1) + if ((contexte = EVP_MD_CTX_new()) == NULL) { + fprintf(stderr, "EVP_MD_CTX_new() failed\n"); close(in_fd); free(chaine); exit(EXIT_FAILURE); } - if (EVP_DigestUpdate(&contexte, chaine, taille_fichier) != 1) + if (EVP_DigestInit(contexte, EVP_sum()) != 1) { + fprintf(stderr, "EVP_DigestInit() failed\n"); + EVP_MD_CTX_free(contexte); close(in_fd); free(chaine); exit(EXIT_FAILURE); } - if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1) + if (EVP_DigestUpdate(contexte, chaine, taille_fichier) != 1) { + fprintf(stderr, "EVP_DigestUpdate() failed\n"); + EVP_MD_CTX_free(contexte); close(in_fd); free(chaine); exit(EXIT_FAILURE); } - EVP_MD_CTX_cleanup(&contexte); + if (EVP_DigestFinal_ex(contexte, somme, &longueur_somme) != 1) + { + fprintf(stderr, "EVP_DigestFinal_ex() failed\n"); + EVP_MD_CTX_free(contexte); + close(in_fd); + free(chaine); + exit(EXIT_FAILURE); + } + + EVP_MD_CTX_free(contexte); free(chaine); for(i = 0; i < longueur_somme; i++)