Fix integrity checking
This commit is contained in:
parent
974fe1f618
commit
1b94d281a6
@ -1,64 +1,54 @@
|
|||||||
//Write a program to compare two file.
|
/* Glacier Integrity Check
|
||||||
#include <stdio.h>
|
* Small program to check file checksums
|
||||||
#include <string.h>
|
*/
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
#include <stdio.h>
|
||||||
{
|
#include<string.h>
|
||||||
FILE *fp1 ;
|
|
||||||
FILE *fp2 ;
|
int main(int argc, char *argv[]) {
|
||||||
|
FILE *fp1;
|
||||||
|
FILE *fp2;
|
||||||
|
|
||||||
int cnt1 = 0;
|
int cnt1 = 0;
|
||||||
int cnt2 = 0;
|
int cnt2 = 0;
|
||||||
int flg = 0;
|
int flg = 0;
|
||||||
|
|
||||||
if( argc < 3 )
|
if (argc < 3) {
|
||||||
{
|
printf("not enough arguments\n");
|
||||||
printf("Insufficient Arguments!!!\n");
|
|
||||||
printf("Please use \"program-name file-name1 file-name2\" format.\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fp1 = fopen(argv[1],"r");
|
fp1 = fopen(argv[1],"r");
|
||||||
if( fp1 == NULL )
|
if (fp1 == NULL) {
|
||||||
{
|
printf("\n%s cannot open file \n",argv[1]);
|
||||||
printf("\n%s File can not be opened : \n",argv[1]);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// move file pointer to end and get total number of bytes
|
|
||||||
fseek(fp1,0,SEEK_END);
|
fseek(fp1,0,SEEK_END);
|
||||||
cnt1 = ftell(fp1);
|
cnt1 = ftell(fp1);
|
||||||
|
|
||||||
fp2 = fopen(argv[2],"r");
|
fp2 = fopen(argv[2],"r");
|
||||||
if( fp2 == NULL )
|
if (fp2 == NULL) {
|
||||||
{
|
printf("\n%s cannot open file \n",argv[2]);
|
||||||
printf("\n%s File can not be opened : \n",argv[2]);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// move file pointer to end and get total number of bytes
|
|
||||||
fseek(fp2,0,SEEK_END);
|
fseek(fp2,0,SEEK_END);
|
||||||
cnt2 = ftell(fp2);
|
cnt2 = ftell(fp2);
|
||||||
|
|
||||||
fseek(fp1,0,SEEK_SET);
|
fseek(fp1,0,SEEK_SET);
|
||||||
fseek(fp2,0,SEEK_SET);
|
fseek(fp2,0,SEEK_SET);
|
||||||
|
|
||||||
// check for the total number of bytes
|
if (cnt1 != cnt2) {
|
||||||
if( cnt1 != cnt2 ){
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else {
|
||||||
else
|
while ( ! feof(fp1)) {
|
||||||
{
|
if (fgetc(fp1) != fgetc(fp2)) {
|
||||||
while( ! feof(fp1) )
|
|
||||||
{
|
|
||||||
if( fgetc(fp1) != fgetc(fp2) )
|
|
||||||
{
|
|
||||||
flg = 1;
|
flg = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (flg) return 1;
|
||||||
if( flg ) return 1;
|
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,4 +57,3 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user