Changeset View
Changeset View
Standalone View
Standalone View
sbin/md5/md5.c
Show First 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | |||||
#ifdef HAVE_CAPSICUM | #ifdef HAVE_CAPSICUM | ||||
cap_rights_t rights; | cap_rights_t rights; | ||||
#endif | #endif | ||||
int ch, fd; | int ch, fd; | ||||
char *p, *string; | char *p, *string; | ||||
char buf[HEX_DIGEST_LENGTH]; | char buf[HEX_DIGEST_LENGTH]; | ||||
size_t len; | size_t len; | ||||
unsigned digest; | unsigned digest; | ||||
const char* progname; | char *progname; | ||||
bool gnu_emu = false; | |||||
if ((progname = strrchr(argv[0], '/')) == NULL) | if ((progname = strrchr(argv[0], '/')) == NULL) | ||||
progname = argv[0]; | progname = argv[0]; | ||||
else | else | ||||
progname++; | progname++; | ||||
/* | |||||
darius-dons.net.au: A comment about why this is done would be good. | |||||
* GNU coreutils has a number of programs named *sum. These produce | |||||
* similar results to the BSD version, but in a different format, | |||||
* similar to BSD's -r flag. We install links to this program with | |||||
* ending 'sum' to provide this compatibility. Check here to see if the | |||||
Done Inline Actionss/proide/provide/ kp: s/proide/provide/ | |||||
* name of the program ends in 'sum', set the flag and drop the 'sum' so | |||||
* the digest lookup works. Also, make -t a nop when running in this mode | |||||
* since that means 'text file' there (though it's a nop in coreutils | |||||
* on unix-like systems). The -c flag conflicts, so it's just disabled | |||||
* in this mode (though in the future it might be implemented). | |||||
*/ | |||||
len = strlen(progname); | |||||
if (len > 3 && strcmp(progname + len - 3, "sum") == 0) { | |||||
progname[len - 3] = '\0'; | |||||
rflag = 1; | |||||
gnu_emu = true; | |||||
} | |||||
for (digest = 0; digest < sizeof(Algorithm)/sizeof(*Algorithm); digest++) | for (digest = 0; digest < sizeof(Algorithm)/sizeof(*Algorithm); digest++) | ||||
if (strcasecmp(Algorithm[digest].progname, progname) == 0) | if (strcasecmp(Algorithm[digest].progname, progname) == 0) | ||||
break; | break; | ||||
if (digest == sizeof(Algorithm)/sizeof(*Algorithm)) | if (digest == sizeof(Algorithm)/sizeof(*Algorithm)) | ||||
digest = 0; | digest = 0; | ||||
failed = 0; | failed = 0; | ||||
checkAgainst = NULL; | checkAgainst = NULL; | ||||
checksFailed = 0; | checksFailed = 0; | ||||
skip = 0; | skip = 0; | ||||
while ((ch = getopt(argc, argv, "c:pqrs:tx")) != -1) | while ((ch = getopt(argc, argv, "bc:pqrs:tx")) != -1) | ||||
switch (ch) { | switch (ch) { | ||||
case 'b': | |||||
break; | |||||
case 'c': | case 'c': | ||||
if (gnu_emu) | |||||
errx(1, "-c check option not supported"); | |||||
checkAgainst = optarg; | checkAgainst = optarg; | ||||
break; | break; | ||||
case 'p': | case 'p': | ||||
pflag = 1; | pflag = 1; | ||||
break; | break; | ||||
case 'q': | case 'q': | ||||
qflag = 1; | qflag = 1; | ||||
break; | break; | ||||
case 'r': | case 'r': | ||||
rflag = 1; | rflag = 1; | ||||
break; | break; | ||||
case 's': | case 's': | ||||
sflag = 1; | sflag = 1; | ||||
string = optarg; | string = optarg; | ||||
break; | break; | ||||
case 't': | case 't': | ||||
if (!gnu_emu) { | |||||
MDTimeTrial(&Algorithm[digest]); | MDTimeTrial(&Algorithm[digest]); | ||||
skip = 1; | skip = 1; | ||||
} /* else: text mode is a nop */ | |||||
break; | break; | ||||
case 'x': | case 'x': | ||||
MDTestSuite(&Algorithm[digest]); | MDTestSuite(&Algorithm[digest]); | ||||
skip = 1; | skip = 1; | ||||
break; | break; | ||||
default: | default: | ||||
usage(&Algorithm[digest]); | usage(&Algorithm[digest]); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | MDTimeTrial(const Algorithm_t *alg) | ||||
/* Stop timer */ | /* Stop timer */ | ||||
getrusage(RUSAGE_SELF, &after); | getrusage(RUSAGE_SELF, &after); | ||||
timersub(&after.ru_utime, &before.ru_utime, &total); | timersub(&after.ru_utime, &before.ru_utime, &total); | ||||
seconds = total.tv_sec + (float) total.tv_usec / 1000000; | seconds = total.tv_sec + (float) total.tv_usec / 1000000; | ||||
printf(" done\n"); | printf(" done\n"); | ||||
printf("Digest = %s", p); | printf("Digest = %s", p); | ||||
printf("\nTime = %f seconds\n", seconds); | printf("\nTime = %f seconds\n", seconds); | ||||
printf("Speed = %f MiB/second\n", (float) TEST_BLOCK_LEN * | printf("Speed = %f MiB/second\n", (float) TEST_BLOCK_LEN * | ||||
impAuthorUnsubmitted Done Inline Actionsthis is a trivial trailing whitespace thing emacs decided to fix... Normally, I'd split it out, but it's trivial enough to be flexible on the style / substance division we normally do) imp: this is a trivial trailing whitespace thing emacs decided to fix... Normally, I'd split it out… | |||||
(float) TEST_BLOCK_COUNT / seconds / (1 << 20)); | (float) TEST_BLOCK_COUNT / seconds / (1 << 20)); | ||||
} | } | ||||
/* | /* | ||||
* Digests a reference suite of strings and prints the results. | * Digests a reference suite of strings and prints the results. | ||||
*/ | */ | ||||
static const char *MDTestInput[MDTESTCOUNT] = { | static const char *MDTestInput[MDTESTCOUNT] = { | ||||
"", | "", | ||||
▲ Show 20 Lines • Show All 179 Lines • Show Last 20 Lines |
A comment about why this is done would be good.