/var/lib/pcp/testsuite/src/sum16.c is in pcp-testsuite 4.0.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
* Copyright (c) 2016 Ken McDonell. All Rights Reserved.
*
* BSD sum(1) replacement.
*
* Algorithm reference: https://en.wikipedia.org/wiki/BSD_checksum
*/
#include <stdio.h>
static
int chksum(FILE *fp, int *bp)
{
int c;
long bytes = 0;
int sum = 0;
while ((c = fgetc(fp)) != EOF) {
sum = (sum >> 1) + ((sum & 1) << 15);
sum = (sum + c ) & 0xffff;
bytes++;
}
*bp = (bytes + 1023) / 1024;
return sum;
}
int
main(int argc, char **argv)
{
int sum;
int blocks;
FILE *fp;
if (argc == 1) {
sum = chksum(stdin, &blocks);
printf("%05d %5d\n", sum, blocks);
}
else {
int i;
for (i = 1; i < argc; i++) {
fp = fopen(argv[i], "r");
if (fp == NULL) {
fprintf(stderr, "%s: fopen failed\n", argv[i]);
}
else {
sum = chksum(fp, &blocks);
printf("%05d %5d %s\n", sum, blocks, argv[i]);
fclose(fp);
}
}
}
return(0);
}
|