| Index: md5/md5cmp.c
|
| diff --git a/tjutil.c b/md5/md5cmp.c
|
| similarity index 68%
|
| copy from tjutil.c
|
| copy to md5/md5cmp.c
|
| index 6618d158cf72965886fca304b337a068aa339e83..dfd60bd396d3a7cd1170ae5330949c082afa2adf 100644
|
| --- a/tjutil.c
|
| +++ b/md5/md5cmp.c
|
| @@ -1,5 +1,5 @@
|
| /*
|
| - * Copyright (C)2011 D. R. Commander. All Rights Reserved.
|
| + * Copyright (C)2013, 2016 D. R. Commander. All Rights Reserved.
|
| *
|
| * Redistribution and use in source and binary forms, with or without
|
| * modification, are permitted provided that the following conditions are met:
|
| @@ -26,41 +26,35 @@
|
| * POSSIBILITY OF SUCH DAMAGE.
|
| */
|
|
|
| -#ifdef _WIN32
|
| +#include <stdio.h>
|
| +#include <string.h>
|
| +#include <sys/types.h>
|
| +#include "./md5.h"
|
| +#include "../tjutil.h"
|
|
|
| -#include <windows.h>
|
| -
|
| -static double getfreq(void)
|
| +int main(int argc, char *argv[])
|
| {
|
| - LARGE_INTEGER freq;
|
| - if(!QueryPerformanceFrequency(&freq)) return 0.0;
|
| - return (double)freq.QuadPart;
|
| -}
|
| -
|
| -static double f=-1.0;
|
| + char *md5sum = NULL, buf[65];
|
|
|
| -double gettime(void)
|
| -{
|
| - LARGE_INTEGER t;
|
| - if(f<0.0) f=getfreq();
|
| - if(f==0.0) return (double)GetTickCount()/1000.;
|
| - else
|
| - {
|
| - QueryPerformanceCounter(&t);
|
| - return (double)t.QuadPart/f;
|
| + if (argc < 3) {
|
| + fprintf(stderr, "USAGE: %s <correct MD5 sum> <file>\n", argv[0]);
|
| + return -1;
|
| }
|
| -}
|
|
|
| -#else
|
| + if (strlen(argv[1]) != 32)
|
| + fprintf(stderr, "WARNING: MD5 hash size is wrong.\n");
|
|
|
| -#include <stdlib.h>
|
| -#include <sys/time.h>
|
| + md5sum = MD5File(argv[2], buf);
|
| + if (!md5sum) {
|
| + perror("Could not obtain MD5 sum");
|
| + return -1;
|
| + }
|
|
|
| -double gettime(void)
|
| -{
|
| - struct timeval tv;
|
| - if(gettimeofday(&tv, NULL)<0) return 0.0;
|
| - else return (double)tv.tv_sec+((double)tv.tv_usec/1000000.);
|
| + if (!strcasecmp(md5sum, argv[1])) {
|
| + fprintf(stderr, "%s: OK\n", argv[2]);
|
| + return 0;
|
| + } else {
|
| + fprintf(stderr, "%s: FAILED. Checksum is %s\n", argv[2], md5sum);
|
| + return -1;
|
| + }
|
| }
|
| -
|
| -#endif
|
|
|