/* Copyright (c) 1979 Regents of the University of California */
* Checksum the indicated directory, creating the file "check.sum"
* with names and int sums stored inside, one per line. The -c
* option causes the directory checksums to be verified.
#define equal(a, b) (strcmp(a, b) == 0)
int cflag
= 1; /* Flag to verify */
char cname
[] = "check.sum"; /* Name of checksum files */
int errs
; /* Error count */
if (argc
== 2 && equal(argv
[1], "-c")) {
* The fork is necessary to preserve the current directory.
char ename
[DIRSIZ
+1], linebuf
[BUFSIZ
];
fprintf(stderr
, "%s:\n", dir
);
if ((cf
= fopen(cname
, "r")) == NULL
) {
while (fgets(linebuf
, BUFSIZ
, cf
) != NULL
) {
for (cp
= linebuf
, cp2
= ename
; *cp
!= ' ';
if ((ef
= fopen(ename
, "r")) == NULL
) {
printf("Checksum error: \"%s\" is %d not %d\n",
if ((cf
= fopen(cname
, "w")) == NULL
) {
if ((df
= fopen("", "r")) == NULL
) {
while (fread((char *) &dirent
, sizeof dirent
, 1, df
) == 1) {
for (cp
= dirent
.d_name
, cp2
= ename
; *cp
&&
cp
-dirent
.d_name
< DIRSIZ
; *cp2
++ = *cp
++)
if ((ef
= fopen(ename
, "r")) == NULL
) {
if ((stb
.st_mode
& S_IFMT
) != S_IFREG
) {
fprintf(cf
, "%s %d\n", ename
, sum
);
* Checksum the passed file. Return the sum of all of its bytes.
while ((c
= getc(f
)) != EOF
)
* Convert the passed string to decimal.
while (any(*cp
, "0123456789"))
sum
= sum
*10 + *cp
++ - '0';