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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/* BC 3.1 source code for something similar to simple diff */
#include <string.h>
#include <dos.h>
#include <dir.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#define COMPAREBUFLEN (1024*16)
char comparebuf1[COMPAREBUFLEN];
char comparebuf2[COMPAREBUFLEN];
int TestAllFiles(char *path1,char *path2)
{
int old_path_len1,old_path_len2;
int done,file1,file2,i;
struct ffblk s;
int len1,len2;
long int pos;
old_path_len1=strlen(path1);
old_path_len2=strlen(path2);
strcat(path1,"*.*");
done=findfirst(path1,&s,0x2f);
path1[old_path_len1]=0;
while(!done)
{
path1[old_path_len1]=0;
path2[old_path_len2]=0;
strcat(path1,s.ff_name);
strcat(path2,s.ff_name);
printf("File in progress %s",path1);
if ((file1=open(path1, O_RDONLY | O_BINARY , S_IREAD))==-1)
{printf("\nCannot open file: %s \n",path1);goto error;}
else if ((file2=open(path2, O_RDONLY | O_BINARY , S_IREAD))==-1)
{printf("\nCannot open file: %s \n",path2);close(file1);goto error;}
else
{
len2=len1=COMPAREBUFLEN;pos=0;
while((len1==COMPAREBUFLEN)&&(len2==COMPAREBUFLEN))
{
if((len1=read(file1,comparebuf1,COMPAREBUFLEN))==-1)
{
printf("\ndisk IO error!: cannot read file %s\n",path1);
goto error_close;
}
if((len2=read(file2,comparebuf2,COMPAREBUFLEN))==-1)
{
printf("\ndisk IO error!: cannot read file %s\n",path2);
goto error_close;
};
if(len1) if(memcmp(comparebuf1,comparebuf2,len1))
{
for(i=0;(i<len1)&&(*(comparebuf1+i)==*(comparebuf2+i));i++);
printf("\nCompare Error %s on pos %X!\n",path1,pos+i);
goto error_close;
}
pos+=len1;
}
if(len1!=len2)
{
printf("\nDifferent lengths of files %s and %s",path1,path2);
error_close:
close(file2);
close(file1);
error:
if(getchar()=='q') return(1);
break;
}else{
printf(" ... compared %ld bytes\n",pos);
close(file2);
close(file1);
};
}
done=findnext(&s);
}
path1[old_path_len1]=0;
path2[old_path_len2]=0;
strcat(path1,"*.*");
done=findfirst(path1,&s,FA_DIREC | 0x7);
path1[old_path_len1]=0;
while(!done)
{
if(*s.ff_name != '.')
{
if((s.ff_attrib & FA_DIREC)!=0)
{
strcat(path1,s.ff_name);
strcat(path1,"\\");
path1[old_path_len1+strlen(s.ff_name)+1]=0;
strcat(path2,s.ff_name);
strcat(path2,"\\");
path1[old_path_len2+strlen(s.ff_name)+1]=0;
TestAllFiles(path1,path2);
path1[old_path_len1]=0;
path2[old_path_len2]=0;
}
}
done=findnext(&s);
}
path1[old_path_len1]=0;
path2[old_path_len2]=0;
return 0;
}
int main(int argc,char *argv[])
{
if(argc<3)
{
printf("usage: cmpdisk <d>: <d>:\n");
return(0);
};
{
char path1[255],path2[255];
strcpy(path1,argv[1]);
strcpy(path2,argv[2]);
TestAllFiles(path1,path2);
};
return(0);
};
|