version 1.1.2.1, 2010/07/12 15:20:41
|
version 1.1.2.3, 2010/09/20 23:07:11
|
Line 21 Usage()
|
Line 21 Usage()
|
"\n", compiled, compiledby, compilehost); |
"\n", compiled, compiledby, compilehost); |
} |
} |
|
|
|
|
int |
int |
calcDir(const char *csDir, u_char **md) |
|
{ |
|
DIR *dir; |
|
struct dirent d, *pd; |
|
MD5_CTX ctx; |
|
|
|
*md = malloc(MD5_DIGEST_LENGTH); |
|
if (!*md) { |
|
printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno)); |
|
return -1; |
|
} else |
|
memset(*md, 0, MD5_DIGEST_LENGTH); |
|
|
|
dir = opendir(csDir); |
|
if (!dir) { |
|
printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno)); |
|
free(*md); |
|
return -1; |
|
} |
|
|
|
MD5_Init(&ctx); |
|
while (!readdir_r(dir, &d, &pd) && pd) { |
|
if (d.d_type == DT_DIR && (!strcmp(d.d_name, ".") || !strcmp(d.d_name, ".."))) |
|
continue; |
|
MD5_Update(&ctx, d.d_name, d.d_namlen); |
|
} |
|
MD5_Final(*md, &ctx); |
|
|
|
closedir(dir); |
|
return 0; |
|
} |
|
|
|
inline int |
|
convMD5(u_char *md, char **str) |
|
{ |
|
register int i; |
|
|
|
*str = malloc(MD5_DIGEST_LENGTH * 2 + 1); |
|
if (!*str) { |
|
printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno)); |
|
return -1; |
|
} else |
|
(*str)[MD5_DIGEST_LENGTH * 2] = 0; |
|
|
|
for (i = 0; i < MD5_DIGEST_LENGTH; i++) |
|
snprintf(&(*str)[i * 2], 3, "%02x", md[i]); |
|
|
|
return 0; |
|
} |
|
|
|
// ---------------------------------------------------- |
|
|
|
int |
|
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
u_char *md[2], mode = 0; |
u_char *md[2], mode = 0; |
Line 108 main(int argc, char **argv)
|
Line 54 main(int argc, char **argv)
|
mode |= 2; |
mode |= 2; |
} |
} |
|
|
if (calcDir(argv[0], &md[0]) == -1) | if (sync_dirCSum(argv[0], &md[0]) == -1) { |
| printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno)); |
return 1; |
return 1; |
if (convMD5(md[0], &str[0]) == -1) { | } |
| str[0] = io_Hex2Ch(md[0], MD5_DIGEST_LENGTH); |
| if (!str[0]) { |
free(md[0]); |
free(md[0]); |
return 1; |
return 1; |
} |
} |
Line 118 main(int argc, char **argv)
|
Line 67 main(int argc, char **argv)
|
|
|
if (mode & 1 && *str[1]) { |
if (mode & 1 && *str[1]) { |
ret |= !strcmp((char*) str[0], (char*) str[1]) << 1; |
ret |= !strcmp((char*) str[0], (char*) str[1]) << 1; |
printf("Result checksum:: %s %s %s\n\n", str[0], ret & 1 ? "==" : "!=", str[1]); | printf("Result checksum:: %s %s %s\n\n", str[0], ret & 2 ? "==" : "!=", str[1]); |
free(str[1]); |
free(str[1]); |
} |
} |
|
|
if (mode & 2 && *szCmp) { |
if (mode & 2 && *szCmp) { |
if (calcDir(szCmp, &md[1]) == -1) | if (sync_dirCSum(szCmp, &md[1]) == -1) { |
| printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno)); |
return 1; |
return 1; |
if (convMD5(md[1], &str[1]) == -1) { | } |
| str[1] = io_Hex2Ch(md[1], MD5_DIGEST_LENGTH); |
| if (!str[1]) { |
free(md[0]); |
free(md[0]); |
free(str[0]); |
free(str[0]); |
free(md[1]); |
free(md[1]); |
Line 134 main(int argc, char **argv)
|
Line 86 main(int argc, char **argv)
|
printf("2.Directory '%s': %s\n", szCmp, str[1]); |
printf("2.Directory '%s': %s\n", szCmp, str[1]); |
|
|
ret |= (!strcmp((char*) str[0], (char*) str[1]) << 2); |
ret |= (!strcmp((char*) str[0], (char*) str[1]) << 2); |
printf("Result directory:: %s %s %s\n\n", argv[0], ret & 2 ? "==" : "!=", szCmp); | printf("Result directory:: %s %s %s\n\n", argv[0], ret & 4 ? "==" : "!=", szCmp); |
|
|
if (str[1]) |
if (str[1]) |
free(str[1]); |
free(str[1]); |