-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <getopt.h>
-
-#include "libbb.h"
-
-/* 1 if any of the files read were the standard input */
-static int have_read_stdin;
-
-/* make a little more readable and avoid using strcmp for just 2 bytes */
-#define IS_STDIN(s) (s[0] == '-' && s[1] == '\0')
-
-/* Calculate and print the rotated checksum and the size in 1K blocks
- of file FILE, or of the standard input if FILE is "-".
- If PRINT_NAME is >1, print FILE next to the checksum and size.
- The checksum varies depending on sizeof (int).
- Return 1 if successful. */
-static int bsd_sum_file(const char *file, int print_name)
-{
- register FILE *fp;
- register int checksum = 0; /* The checksum mod 2^16. */
- register uintmax_t total_bytes = 0; /* The number of bytes. */
- register int ch; /* Each character read. */
-
- if (IS_STDIN(file)) {
- fp = stdin;
- have_read_stdin = 1;
- } else {
- fp = fopen(file, "r");
- if (fp == NULL) {
- bb_perror_msg("%s", file);
- return 0;
- }
- }
-
- while ((ch = getc(fp)) != EOF) {
- ++total_bytes;
- checksum = (checksum >> 1) + ((checksum & 1) << 15);
- checksum += ch;
- checksum &= 0xffff; /* Keep it within bounds. */
- }