]> andersk Git - moira.git/blob - update/checksum.c
6347c16e6a5d11d0d0b49f50950818b45158ceb3
[moira.git] / update / checksum.c
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
12
13 #include <mit-copyright.h>
14 #include <stdio.h>
15 #include <sys/types.h>
16 #include <sys/file.h>
17
18 /*
19  * checksum_fd(fd)
20  * returns 24-bit checksum of bytes in file
21  */
22
23 int checksum_file(char *path)
24 {
25   register int sum;
26   register int ch;
27   register FILE *f;
28
29   sum = 0;
30   f = fopen(path, "r");
31   while ((ch = getc(f)) != EOF)
32     sum = (sum + ch) & ((1 << 24) - 1);
33   fclose(f);
34   return sum;
35 }
This page took 0.025685 seconds and 3 git commands to generate.