]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * $Source$ | |
3 | * $Header$ | |
4 | */ | |
5 | /* (c) Copyright 1988 by the Massachusetts Institute of Technology. */ | |
6 | /* For copying and distribution information, please see the file */ | |
7 | /* <mit-copyright.h>. */ | |
8 | ||
9 | #ifndef lint | |
10 | static char *rcsid_checksum_c = "$Header$"; | |
11 | #endif lint | |
12 | ||
13 | #include <mit-copyright.h> | |
14 | #include <stdio.h> | |
15 | #include <sys/file.h> | |
16 | ||
17 | /* | |
18 | * checksum_fd(fd) | |
19 | * returns 24-bit checksum of bytes in file | |
20 | */ | |
21 | ||
22 | int | |
23 | checksum_file(path) | |
24 | char *path; | |
25 | { | |
26 | register int sum; | |
27 | register int ch; | |
28 | register FILE *f; | |
29 | ||
30 | sum = 0; | |
31 | f = fopen(path, "r"); | |
32 | while ((ch = getc(f)) != EOF) { | |
33 | sum = (sum + ch) & ((1<<24)-1); | |
34 | } | |
35 | fclose(f); | |
36 | return(sum); | |
37 | } |