#include
#include
#define BUF_SIZE 1024
int check(gchar* path,gchar sum[128]);
int main(int argc,char** argv){
gchar check_sum_s_a[128];
gchar check_sum_s_b[128];
int equal = 0;
check(argv[1],check_sum_s_a);
check(argv[2],check_sum_s_b);
equal = g_ascii_strcasecmp(check_sum_s_a,check_sum_s_b);
if(equal == 0){
g_print("%s and %s are equal!\n",argv[1],argv[2]);
}
else{
g_print("%s = %s\n%s = %s\n",argv[1],check_sum_s_a,argv[2],check_sum_s_b);
}
return 0;
}
int check(gchar* path,gchar* sum){
#define BUF_SIZE 1024
gchar buf[BUF_SIZE];
guint len = 0;
GChecksum* check_sum_a = g_checksum_new(G_CHECKSUM_MD5);
FILE* fa = fopen(path,"rb");
if(fa == NULL) return -1;
while((len = fread(buf,1,BUF_SIZE,fa)) > 0){
g_checksum_update(check_sum_a,buf,len);
}
const gchar* check_sum_s_a = g_checksum_get_string(check_sum_a);
g_stpcpy(sum,check_sum_s_a);
g_checksum_free(check_sum_a);
fclose(fa);
#undef BUF_SIZE
}