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