]>
Commit | Line | Data |
---|---|---|
de56407f | 1 | /* |
2 | * $Source$ | |
3 | * $Header$ | |
4 | */ | |
5 | ||
6 | #ifndef lint | |
7 | static char *rcsid_checksum_c = "$Header$"; | |
8 | #endif lint | |
9 | ||
10 | #include <stdio.h> | |
11 | #include <sys/file.h> | |
12 | ||
13 | /* | |
14 | * checksum_fd(fd) | |
15 | * returns 24-bit checksum of bytes in file | |
16 | */ | |
17 | ||
18 | int | |
19 | checksum_fd(fd1) | |
20 | int fd1; | |
21 | { | |
22 | int fd; | |
23 | register int sum; | |
24 | register int ch; | |
25 | register FILE *f; | |
26 | ||
27 | fd = dup(fd1); | |
28 | sum = 0; | |
29 | (void) lseek(fd, 0, L_SET); | |
30 | f = fdopen(fd, "r"); | |
31 | while ((ch = getc(f)) != EOF) { | |
32 | sum = (sum + ch) & ((1<<24)-1); | |
33 | } | |
34 | fclose(f); | |
35 | return(sum); | |
36 | } |